Skip to content

Commit 3d7c9d2

Browse files
committed
try to be phpunit 9.x compatible
1 parent d929ac4 commit 3d7c9d2

File tree

4 files changed

+53
-24
lines changed

4 files changed

+53
-24
lines changed

phpunit.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="vendor/phpunit/phpunit/phpunit.xsd" bootstrap="tests/bootstrap.php" cacheResult="false" colors="true" executionOrder="random" failOnRisky="true" failOnWarning="true" failOnEmptyTestSuite="true" beStrictAboutChangesToGlobalState="true" beStrictAboutOutputDuringTests="true" cacheDirectory="tmp/.phpunit.cache" beStrictAboutCoverageMetadata="true">
3+
<extensions>
4+
<bootstrap class="PHPStan\Testing\PHPUnit\PHPUnitExtension"/>
5+
</extensions>
36
<testsuites>
47
<testsuite name="PHPStan">
58
<directory suffix="Test.php">tests/PHPStan</directory>
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Testing\PHPUnit;
4+
5+
use PHPStan\Testing\PHPStanTestCase;
6+
use PHPUnit\Event\Test\DataProviderMethodCalled;
7+
use PHPUnit\Event\Test\DataProviderMethodCalledSubscriber;
8+
use function is_a;
9+
10+
class InitContainerBeforeDataProviderSubscriber implements DataProviderMethodCalledSubscriber
11+
{
12+
13+
public function notify(DataProviderMethodCalled $event): void
14+
{
15+
$testClassName = $event->testMethod()->className();
16+
17+
if (!is_a($testClassName, PhpStanTestCase::class, true)) {
18+
return;
19+
}
20+
21+
$testClassName::getContainer();
22+
}
23+
24+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php declare(strict_types = 1);
2+
3+
namespace PHPStan\Testing\PHPUnit;
4+
5+
use Override;
6+
use PHPUnit\Runner\Extension\Extension;
7+
use PHPUnit\Runner\Extension\Facade;
8+
use PHPUnit\Runner\Extension\ParameterCollection;
9+
use PHPUnit\TextUI\Configuration\Configuration;
10+
11+
final class PHPUnitExtension implements Extension
12+
{
13+
14+
#[Override]
15+
public function bootstrap(
16+
Configuration $configuration,
17+
Facade $facade,
18+
ParameterCollection $parameters,
19+
): void
20+
{
21+
$facade->registerSubscriber(
22+
new InitContainerBeforeDataProviderSubscriber(),
23+
);
24+
}
25+
26+
}

tests/bootstrap.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
<?php declare(strict_types = 1);
22

3-
use PHPStan\Testing\PHPStanTestCase;
4-
use PHPUnit\Event\Facade;
5-
use PHPUnit\Event\Test\DataProviderMethodCalled;
6-
use PHPUnit\Event\Test\DataProviderMethodCalledSubscriber;
7-
83
error_reporting(E_ALL);
94

105
require_once __DIR__ . '/../vendor/autoload.php';
@@ -24,22 +19,3 @@ public function doFoo($i)
2419
}
2520
2621
}');
27-
28-
class InitContainerBeforeDataProvider implements DataProviderMethodCalledSubscriber
29-
{
30-
31-
public function notify(DataProviderMethodCalled $event): void
32-
{
33-
$testClassName = $event->testMethod()->className();
34-
35-
if (!is_a($testClassName, PhpStanTestCase::class, true)) {
36-
return;
37-
}
38-
39-
$testClassName::getContainer();
40-
}
41-
42-
}
43-
44-
45-
Facade::instance()->registerSubscriber(new InitContainerBeforeDataProvider());

0 commit comments

Comments
 (0)