diff --git a/build/old-phpunit.neon b/build/old-phpunit.neon index 634de52560..52e9beb14d 100644 --- a/build/old-phpunit.neon +++ b/build/old-phpunit.neon @@ -1,4 +1,7 @@ parameters: + excludePaths: + - ../src/Testing/PHPUnit/* + ignoreErrors: - message: '#^Instanceof references internal interface PHPUnit\\Exception\.$#' diff --git a/phpunit.xml b/phpunit.xml index 062728282f..59224af805 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,5 +1,8 @@ + + + tests/PHPStan diff --git a/src/Testing/PHPStanTestCase.php b/src/Testing/PHPStanTestCase.php index 7cf7d673b6..d294f81d24 100644 --- a/src/Testing/PHPStanTestCase.php +++ b/src/Testing/PHPStanTestCase.php @@ -2,7 +2,6 @@ namespace PHPStan\Testing; -use Override; use PHPStan\Analyser\ConstantResolver; use PHPStan\Analyser\DirectInternalScopeFactory; use PHPStan\Analyser\Error; @@ -97,12 +96,6 @@ public static function getContainer(): Container return self::$containers[$cacheKey]; } - #[Override] - public static function setUpBeforeClass(): void - { - self::getContainer(); - } - /** * @return string[] */ diff --git a/src/Testing/PHPUnit/InitContainerBeforeDataProviderSubscriber.php b/src/Testing/PHPUnit/InitContainerBeforeDataProviderSubscriber.php new file mode 100644 index 0000000000..525984fb4c --- /dev/null +++ b/src/Testing/PHPUnit/InitContainerBeforeDataProviderSubscriber.php @@ -0,0 +1,26 @@ +testMethod()->className(); + + if (!is_a($testClassName, PhpStanTestCase::class, true)) { + return; + } + + $testClassName::getContainer(); + } + +} diff --git a/src/Testing/PHPUnit/PHPStanPHPUnitExtension.php b/src/Testing/PHPUnit/PHPStanPHPUnitExtension.php new file mode 100644 index 0000000000..ff52d637b9 --- /dev/null +++ b/src/Testing/PHPUnit/PHPStanPHPUnitExtension.php @@ -0,0 +1,26 @@ +registerSubscriber( + new InitContainerBeforeDataProviderSubscriber(), + ); + } + +}