-
-
Notifications
You must be signed in to change notification settings - Fork 230
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: PHPunit extensions must run before data providers (#917)
* test: add a failing test case * Run extension before loading the suite --------- Co-authored-by: Filippo Tessarotto <[email protected]>
- Loading branch information
Showing
8 changed files
with
137 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
test/fixtures/extension_run_before_data_provider/ExtensionMustRunBeforeDataProviderTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ParaTest\Tests\fixtures\extension_run_before_data_provider; | ||
|
||
use PHPUnit\Framework\Attributes\DataProvider; | ||
use PHPUnit\Framework\TestCase; | ||
use RuntimeException; | ||
|
||
final class ExtensionMustRunBeforeDataProviderTest extends TestCase | ||
{ | ||
public static string $var = 'foo'; | ||
|
||
#[DataProvider('provide')] | ||
public function testExtensionMustRunBeforeDataProvider(string $var): void | ||
{ | ||
self::assertSame('bar', $var); | ||
} | ||
|
||
/** @return iterable<array{string}> */ | ||
public static function provide(): iterable | ||
{ | ||
if (self::$var !== 'bar') { | ||
throw new RuntimeException('Extension did not run before data provider.'); | ||
} | ||
|
||
yield [self::$var]; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
test/fixtures/extension_run_before_data_provider/PHPUnitExtension.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace ParaTest\Tests\fixtures\extension_run_before_data_provider; | ||
|
||
use PHPUnit\Event; | ||
use PHPUnit\Runner; | ||
use PHPUnit\TextUI; | ||
|
||
final class PHPUnitExtension implements Runner\Extension\Extension | ||
{ | ||
public function bootstrap( | ||
TextUI\Configuration\Configuration $configuration, | ||
Runner\Extension\Facade $facade, | ||
Runner\Extension\ParameterCollection $parameters, | ||
): void { | ||
$facade->registerSubscribers( | ||
new class implements Event\Test\DataProviderMethodCalledSubscriber { | ||
public function notify(Event\Test\DataProviderMethodCalled $event): void | ||
{ | ||
ExtensionMustRunBeforeDataProviderTest::$var = 'bar'; | ||
} | ||
}, | ||
); | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
test/fixtures/extension_run_before_data_provider/phpunit.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<phpunit> | ||
<testsuites> | ||
<testsuite name="ExtensionMustRunBeforeDataProviderTest"> | ||
<file>ExtensionMustRunBeforeDataProviderTest.php</file> | ||
</testsuite> | ||
</testsuites> | ||
<extensions> | ||
<bootstrap class="ParaTest\Tests\fixtures\extension_run_before_data_provider\PHPUnitExtension" /> | ||
</extensions> | ||
</phpunit> |