Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 086ee29

Browse files
authored
Init container before DataProvider is called (#4342)
1 parent dd41088 commit 086ee29

File tree

5 files changed

+58
-7
lines changed

5 files changed

+58
-7
lines changed

‎build/old-phpunit.neon‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
parameters:
2+
excludePaths:
3+
- ../src/Testing/PHPUnit/*
4+
25
ignoreErrors:
36
-
47
message: '#^Instanceof references internal interface PHPUnit\\Exception\.$#'

‎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\PHPStanPHPUnitExtension"/>
5+
</extensions>
36
<testsuites>
47
<testsuite name="PHPStan">
58
<directory suffix="Test.php">tests/PHPStan</directory>

‎src/Testing/PHPStanTestCase.php‎

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace PHPStan\Testing;
44

5-
use Override;
65
use PHPStan\Analyser\ConstantResolver;
76
use PHPStan\Analyser\DirectInternalScopeFactory;
87
use PHPStan\Analyser\Error;
@@ -97,12 +96,6 @@ public static function getContainer(): Container
9796
return self::$containers[$cacheKey];
9897
}
9998

100-
#[Override]
101-
public static function setUpBeforeClass(): void
102-
{
103-
self::getContainer();
104-
}
105-
10699
/**
107100
* @return string[]
108101
*/
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 PHPStan\Testing\PHPStanTestCase;
7+
use PHPUnit\Event\Test\DataProviderMethodCalled;
8+
use PHPUnit\Event\Test\DataProviderMethodCalledSubscriber;
9+
use function is_a;
10+
11+
final class InitContainerBeforeDataProviderSubscriber implements DataProviderMethodCalledSubscriber
12+
{
13+
14+
#[Override]
15+
public function notify(DataProviderMethodCalled $event): void
16+
{
17+
$testClassName = $event->testMethod()->className();
18+
19+
if (!is_a($testClassName, PhpStanTestCase::class, true)) {
20+
return;
21+
}
22+
23+
$testClassName::getContainer();
24+
}
25+
26+
}
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 PHPStanPHPUnitExtension 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+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /