File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33namespace PHPStan \Testing ;
44
5+ use Override ;
56use PHPStan \Analyser \ConstantResolver ;
67use PHPStan \Analyser \DirectInternalScopeFactoryFactory ;
78use PHPStan \Analyser \Error ;
@@ -40,6 +41,24 @@ abstract class PHPStanTestCase extends TestCase
4041
4142 use PHPStanTestCaseTrait;
4243
44+ /**
45+ * Re-register the runtime container as the global static reflection provider before
46+ * every test. Enable this in tests that construct Type objects directly and assert
47+ * PHP-version-dependent reflection results, so a foreign PhpVersion leaked by another
48+ * test can't flake them. See https://github.com/phpstan/phpstan/issues/14860
49+ */
50+ protected bool $ reinitializeContainerBeforeEachTest = false ;
51+
52+ #[Override]
53+ protected function setUp (): void
54+ {
55+ if (!$ this ->reinitializeContainerBeforeEachTest ) {
56+ return ;
57+ }
58+
59+ self ::getContainer ();
60+ }
61+
4362 public static function getParser (): Parser
4463 {
4564 /** @var Parser $parser */
Original file line number Diff line number Diff line change 44
55use Closure ;
66use DateInterval ;
7- use Override ;
87use PHPStan \Testing \PHPStanTestCase ;
98use PHPStan \TrinaryLogic ;
109use PHPStan \Type \CallableType ;
2423class HasPropertyTypeTest extends PHPStanTestCase
2524{
2625
27- #[Override]
28- protected function setUp (): void
29- {
30- // Pin the runtime container so a foreign PhpVersion leaked by another test
31- // can't flake the version-dependent Closure data set below.
32- // See https://github.com/phpstan/phpstan/issues/14860
33- self ::getContainer ();
34- }
26+ // Pin the runtime container so a foreign PhpVersion leaked by another test
27+ // can't flake the version-dependent Closure data set below.
28+ // See https://github.com/phpstan/phpstan/issues/14860
29+ protected bool $ reinitializeContainerBeforeEachTest = true ;
3530
3631 public static function dataIsSuperTypeOf (): array
3732 {
Original file line number Diff line number Diff line change 66use DateTimeInterface ;
77use Exception ;
88use Iterator ;
9- use Override ;
109use PHPStan \Testing \PHPStanTestCase ;
1110use PHPStan \TrinaryLogic ;
1211use PHPStan \Type \IntegerType ;
3332class GenericObjectTypeTest extends PHPStanTestCase
3433{
3534
36- #[Override]
37- protected function setUp (): void
38- {
39- // Pin the runtime container so a foreign PhpVersion leaked by another test
40- // can't flake the version-dependent data sets (reflected variance of built-in
41- // generics). See https://github.com/phpstan/phpstan/issues/14860
42- self ::getContainer ();
43- }
35+ // Pin the runtime container so a foreign PhpVersion leaked by another test
36+ // can't flake the version-dependent data sets (reflected variance of built-in
37+ // generics). See https://github.com/phpstan/phpstan/issues/14860
38+ protected bool $ reinitializeContainerBeforeEachTest = true ;
4439
4540 public static function dataIsSuperTypeOf (): array
4641 {
Original file line number Diff line number Diff line change 2323use Iterator ;
2424use LogicException ;
2525use ObjectTypeEnums \FooEnum ;
26- use Override ;
2726use PHPStan \Testing \PHPStanTestCase ;
2827use PHPStan \TrinaryLogic ;
2928use PHPStan \Type \Accessory \HasMethodType ;
5251class ObjectTypeTest extends PHPStanTestCase
5352{
5453
55- #[Override]
56- protected function setUp (): void
57- {
58- // Pin the runtime container so a foreign PhpVersion leaked by another test
59- // can't flake the version-dependent Closure data sets (dynamic-property
60- // handling). See https://github.com/phpstan/phpstan/issues/14860
61- self ::getContainer ();
62- }
54+ // Pin the runtime container so a foreign PhpVersion leaked by another test
55+ // can't flake the version-dependent Closure data sets (dynamic-property
56+ // handling). See https://github.com/phpstan/phpstan/issues/14860
57+ protected bool $ reinitializeContainerBeforeEachTest = true ;
6358
6459 public static function dataIsIterable (): array
6560 {
Original file line number Diff line number Diff line change 1414use InvalidArgumentException ;
1515use Iterator ;
1616use ObjectShapesAcceptance \ClassWithFooIntProperty ;
17- use Override ;
1817use PHPStan \DependencyInjection \BleedingEdgeToggle ;
1918use PHPStan \Fixture \FinalClass ;
2019use PHPStan \Generics \FunctionsAssertType \C ;
7473class TypeCombinatorTest extends PHPStanTestCase
7574{
7675
77- #[Override]
78- protected function setUp (): void
79- {
80- // Pin the runtime container so a foreign PhpVersion leaked by another test
81- // can't flake the version-dependent data sets (dynamic-property handling of
82- // final classes). See https://github.com/phpstan/phpstan/issues/14860
83- self ::getContainer ();
84- }
76+ // Pin the runtime container so a foreign PhpVersion leaked by another test
77+ // can't flake the version-dependent data sets (dynamic-property handling of
78+ // final classes). See https://github.com/phpstan/phpstan/issues/14860
79+ protected bool $ reinitializeContainerBeforeEachTest = true ;
8580
8681 public static function dataAddNull (): array
8782 {
You can’t perform that action at this time.
0 commit comments