From 343c80980fb4477eda701c2f183a184f7e64dc41 Mon Sep 17 00:00:00 2001 From: Nicolas PHILIPPE Date: Mon, 9 Dec 2024 13:52:32 +0100 Subject: [PATCH] test: add a failing test case --- test/Unit/WrapperRunner/WrapperRunnerTest.php | 21 +++++++++++++ ...ExtensionMustRunBeforeDataProviderTest.php | 30 +++++++++++++++++++ .../PHPUnitExtension.php | 27 +++++++++++++++++ .../phpunit.xml | 10 +++++++ 4 files changed, 88 insertions(+) create mode 100644 test/fixtures/extension_run_before_data_provider/ExtensionMustRunBeforeDataProviderTest.php create mode 100644 test/fixtures/extension_run_before_data_provider/PHPUnitExtension.php create mode 100644 test/fixtures/extension_run_before_data_provider/phpunit.xml diff --git a/test/Unit/WrapperRunner/WrapperRunnerTest.php b/test/Unit/WrapperRunner/WrapperRunnerTest.php index 91f151f9..b51f97b0 100644 --- a/test/Unit/WrapperRunner/WrapperRunnerTest.php +++ b/test/Unit/WrapperRunner/WrapperRunnerTest.php @@ -777,6 +777,27 @@ public function testProcessIsolation(): void self::assertSame(RunnerInterface::SUCCESS_EXIT, $runnerResult->exitCode); } + public function testExtensionRunBeforeDataProvider(): void + { + $this->bareOptions['--configuration'] = $this->fixture('extension_run_before_data_provider' . DIRECTORY_SEPARATOR . 'phpunit.xml'); + + $runnerResult = $this->runRunner(); + + $expectedOutput = <<bareOptions['--configuration']} + +. 1 / 1 (100%) + +Time: %s, Memory: %s MB + +OK%a +EOF; + self::assertStringMatchesFormat($expectedOutput, $runnerResult->output); + self::assertEquals(RunnerInterface::SUCCESS_EXIT, $runnerResult->exitCode); + } + private static function sorted(string $from): string { $from = explode(PHP_EOL, $from); diff --git a/test/fixtures/extension_run_before_data_provider/ExtensionMustRunBeforeDataProviderTest.php b/test/fixtures/extension_run_before_data_provider/ExtensionMustRunBeforeDataProviderTest.php new file mode 100644 index 00000000..09d1f7b7 --- /dev/null +++ b/test/fixtures/extension_run_before_data_provider/ExtensionMustRunBeforeDataProviderTest.php @@ -0,0 +1,30 @@ + */ + public static function provide(): iterable + { + if (self::$var !== 'bar') { + throw new RuntimeException('Extension did not run before data provider.'); + } + + yield [self::$var]; + } +} diff --git a/test/fixtures/extension_run_before_data_provider/PHPUnitExtension.php b/test/fixtures/extension_run_before_data_provider/PHPUnitExtension.php new file mode 100644 index 00000000..4bfacc88 --- /dev/null +++ b/test/fixtures/extension_run_before_data_provider/PHPUnitExtension.php @@ -0,0 +1,27 @@ +registerSubscribers( + new class implements Event\Test\DataProviderMethodCalledSubscriber { + public function notify(Event\Test\DataProviderMethodCalled $event): void + { + ExtensionMustRunBeforeDataProviderTest::$var = 'bar'; + } + }, + ); + } +} diff --git a/test/fixtures/extension_run_before_data_provider/phpunit.xml b/test/fixtures/extension_run_before_data_provider/phpunit.xml new file mode 100644 index 00000000..ae566689 --- /dev/null +++ b/test/fixtures/extension_run_before_data_provider/phpunit.xml @@ -0,0 +1,10 @@ + + + + ExtensionMustRunBeforeDataProviderTest.php + + + + + +