Skip to content

Commit

Permalink
test: add a failing test case
Browse files Browse the repository at this point in the history
  • Loading branch information
nikophil committed Dec 9, 2024
1 parent 64b784e commit 343c809
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/Unit/WrapperRunner/WrapperRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <<<EOF
Processes: %s
Runtime: PHP %s
Configuration: {$this->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);
Expand Down
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];
}
}
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 test/fixtures/extension_run_before_data_provider/phpunit.xml
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>

0 comments on commit 343c809

Please sign in to comment.