-
Notifications
You must be signed in to change notification settings - Fork 546
Init container before DataProvider is called #4342
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
Changes from 4 commits
9f20e61
d929ac4
3d7c9d2
fb04982
6bd06e1
f4ce2bf
0f1d4da
8f1d82d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace PHPStan\Testing\PHPUnit; | ||
|
|
||
| use Override; | ||
| use PHPStan\Testing\PHPStanTestCase; | ||
| use PHPUnit\Event\Test\DataProviderMethodCalled; | ||
| use PHPUnit\Event\Test\DataProviderMethodCalledSubscriber; | ||
| use function is_a; | ||
|
|
||
| final class InitContainerBeforeDataProviderSubscriber implements DataProviderMethodCalledSubscriber | ||
|
Check failure on line 11 in src/Testing/PHPUnit/InitContainerBeforeDataProviderSubscriber.php
|
||
| { | ||
|
|
||
| #[Override] | ||
| public function notify(DataProviderMethodCalled $event): void | ||
|
Check failure on line 15 in src/Testing/PHPUnit/InitContainerBeforeDataProviderSubscriber.php
|
||
| { | ||
| $testClassName = $event->testMethod()->className(); | ||
|
Check failure on line 17 in src/Testing/PHPUnit/InitContainerBeforeDataProviderSubscriber.php
|
||
|
|
||
| if (!is_a($testClassName, PhpStanTestCase::class, true)) { | ||
| return; | ||
| } | ||
|
|
||
| $testClassName::getContainer(); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| <?php declare(strict_types = 1); | ||
|
|
||
| namespace PHPStan\Testing\PHPUnit; | ||
|
|
||
| use Override; | ||
| use PHPUnit\Runner\Extension\Extension; | ||
| use PHPUnit\Runner\Extension\Facade; | ||
| use PHPUnit\Runner\Extension\ParameterCollection; | ||
| use PHPUnit\TextUI\Configuration\Configuration; | ||
|
|
||
| final class PHPUnitExtension implements Extension | ||
|
Check failure on line 11 in src/Testing/PHPUnit/PHPUnitExtension.php
|
||
|
||
| { | ||
|
|
||
| #[Override] | ||
| public function bootstrap( | ||
|
Check failure on line 15 in src/Testing/PHPUnit/PHPUnitExtension.php
|
||
| Configuration $configuration, | ||
|
Check failure on line 16 in src/Testing/PHPUnit/PHPUnitExtension.php
|
||
| Facade $facade, | ||
|
Check failure on line 17 in src/Testing/PHPUnit/PHPUnitExtension.php
|
||
| ParameterCollection $parameters, | ||
|
Check failure on line 18 in src/Testing/PHPUnit/PHPUnitExtension.php
|
||
| ): void | ||
| { | ||
| $facade->registerSubscriber( | ||
|
Check failure on line 21 in src/Testing/PHPUnit/PHPUnitExtension.php
|
||
| new InitContainerBeforeDataProviderSubscriber(), | ||
| ); | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in case extension developer have to deal with the same race condition problems, we could instruct them to use the extension, which takes care of bootstrapping/re-building the container for them