1313class PHPUnitVersionDetector
1414{
1515
16- private bool $ initialized = false ;
17-
18- private ?int $ majorVersion = null ;
16+ private ?PHPUnitVersion $ PHPUnitVersion = null ;
1917
2018 private ReflectionProvider $ reflectionProvider ;
2119
@@ -24,19 +22,13 @@ public function __construct(ReflectionProvider $reflectionProvider)
2422 $ this ->reflectionProvider = $ reflectionProvider ;
2523 }
2624
27- public function isPHPUnit10OrNewer (): bool
28- {
29- $ majorVersion = $ this ->getMajorVersion ();
30- return $ majorVersion !== null && $ majorVersion >= 10 ;
31- }
32-
33- private function getMajorVersion (): ?int
25+ public function getPHPUnitVersion (): PHPUnitVersion
3426 {
35- if ($ this ->initialized ) {
36- return $ this ->majorVersion ;
27+ if ($ this ->PHPUnitVersion !== null ) {
28+ return $ this ->PHPUnitVersion ;
3729 }
38- $ this ->initialized = true ;
3930
31+ $ majorVersion = null ;
4032 if ($ this ->reflectionProvider ->hasClass (TestCase::class)) {
4133 $ testCase = $ this ->reflectionProvider ->getClass (TestCase::class);
4234 $ file = $ testCase ->getFileName ();
@@ -49,14 +41,14 @@ private function getMajorVersion(): ?int
4941 $ json = json_decode ($ composerJson , true );
5042 $ version = $ json ['extra ' ]['branch-alias ' ]['dev-main ' ] ?? null ;
5143 if ($ version !== null ) {
52- $ this -> majorVersion = (int ) explode ('. ' , $ version )[0 ];
44+ $ majorVersion = (int ) explode ('. ' , $ version )[0 ];
5345 }
5446 }
5547 }
5648 }
5749 }
5850
59- return $ this ->majorVersion ;
51+ return $ this ->PHPUnitVersion = new PHPUnitVersion ( $ majorVersion) ;
6052 }
6153
6254}
0 commit comments