Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PHPUnit 9.0] Add TestListenerToHooksRector #1270

Merged
merged 1 commit into from Mar 31, 2019
Merged

Conversation

TomasVotruba
Copy link
Member

@TomasVotruba TomasVotruba commented Mar 27, 2019

Closes #1266

Migration path for sebastianbergmann/phpunit#3389

How to apply?

composer require rector/rector --dev
vendor/bin/rector process tests --level phpunit90

Showcase

 <?php

 namespace App\Tests;

-use PHPUnit\Framework\TestListener;
-
-final class BeforeListHook implements TestListener
+final class BeforeListHook implements \PHPUnit\Runner\BeforeTestHook, \PHPUnit\Runner\AfterTestHook
 {
-    public function addError(Test $test, \Throwable $t, float $time): void
-    {
-    }
-
-    public function addWarning(Test $test, Warning $e, float $time): void
-    {
-    }
-
-    public function addFailure(Test $test, AssertionFailedError $e, float $time): void
-    {
-    }
-
-    public function addIncompleteTest(Test $test, \Throwable $t, float $time): void
-    {
-    }
-
-    public function addRiskyTest(Test $test, \Throwable $t, float $time): void
-    {
-    }
-
-    public function addSkippedTest(Test $test, \Throwable $t, float $time): void
-    {
-    }
-
-    public function startTestSuite(TestSuite $suite): void
-    {
-    }
-
-    public function endTestSuite(TestSuite $suite): void
-    {
-    }

-    public function startTest(Test $test): void
+    public function executeBeforeTest(Test $test): void
     {
         echo 'start test!';
     }

-    public function endTest(Test $test, float $time): void
+    public function executeAfterTest(Test $test, float $time): void
     {
         echo $time;
     }
 }

@joesaunderson
Copy link

@TomasVotruba in the hook, how are you getting a Test type? The new hooks pass a string?

@TomasVotruba
Copy link
Member Author

Not sure what you mean. Code sample?

@joesaunderson
Copy link

joesaunderson commented Jul 3, 2019

Rector change:

public function executeBeforeTest(Test $test): void
     {
         echo 'start test!';
     }

PHPUnit Interface:

interface BeforeTestHook extends TestHook
{
    public function executeBeforeTest(string $test): void;
}

@TomasVotruba
Copy link
Member Author

What's expected change?

@joesaunderson
Copy link

That’s the point, I don’t think it’s a straightforward change that can be done automatically.

But changing as above will not work (string will be passed instead of Test type)

@TomasVotruba
Copy link
Member Author

TomasVotruba commented Jul 3, 2019

So what is expected behavior for such a listener? No change?

It's deprecated and will be removed, so there must be some upgrade path.

@joesaunderson
Copy link

I’m not sure on the upgrade path, see here for changes sebastianbergmann/phpunit#3388

But I do know, that the new interfaces no longer pass the Test type around.

@joesaunderson
Copy link

@sebastianbergmann what would the upgrade path be for this change?

Am I right in thinking the changes above do not correctly implement the interfaces?

TomasVotruba added a commit that referenced this pull request Nov 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[PHPUnit] Listener to hooks
2 participants