Skip to content

[PHPUnit90] Use hook param types in TestListenerToHooksRector, skip when the body uses the original objects - #863

Merged
TomasVotruba merged 1 commit into
mainfrom
fix-test-listener-hook-param-type
Dec 4, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
fix-test-listener-hook-param-type

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

TestListenerToHooksRector renamed e.g. startTest(Test $test) to executeBeforeTest() but kept the Test $test param. The PHPUnit 9 hook interfaces declare executeBeforeTest(string $test), executeAfterTest(string $test, float $time), executeAfterTestError(string $test, string $message, float $time) etc., so the refactored class fataled on load with "Declaration ... must be compatible".

Now the renamed method gets the hook's param types (suite hooks get no params):

-public function startTest(Test $test): void
+public function executeBeforeTest(string $test): void

-public function addError(Test $test, \Throwable $t, float $time): void
+public function executeAfterTestError(string $test, string $t, float $time): void

When a method body uses a param whose type changes (e.g. $test->getName(), $t->getMessage(), $suite), the class is skipped, as the hook passes strings and the body would break.

@TomasVotruba
TomasVotruba merged commit 3d7ba7a into main Dec 4, 2026
15 checks passed
@TomasVotruba
TomasVotruba deleted the fix-test-listener-hook-param-type branch December 4, 2026 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant