Skip to content

Commit 1d4934f

Browse files
localheinzmvorisek
andcommitted
Fix: Detect PHPUnit version based on series instead of identifier
Co-authored-by: Andreas Möller <[email protected]> Co-authored-by: Michael Voříšek <[email protected]>
1 parent 7b69bc5 commit 1d4934f

File tree

10 files changed

+272
-847
lines changed

10 files changed

+272
-847
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ For a full diff see [`2.4.0...main`][2.4.0...main].
1414
- Added support for PHP 8.0 ([#375]), by [@localheinz] and [@mvorisek]
1515
- Added support for PHP 7.4 ([#390]), by [@localheinz] and [@mvorisek]
1616

17+
### Changed
18+
19+
- Improved detection of PHPUnit version ([#393]), by [@localheinz] and [@mvorisek]
20+
1721
## [`2.4.0`][2.4.0]
1822

1923
For a full diff see [`2.3.2...2.4.0`][2.3.2...2.4.0].
@@ -204,6 +208,7 @@ For a full diff see [`7afa59c...1.0.0`][7afa59c...1.0.0].
204208
[#367]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/367
205209
[#375]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/375
206210
[#390]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/390
211+
[#393]: https://github.com/ergebnis/phpunit-slow-test-detector/pull/393
207212

208213
[@HypeMC]: https://github.com/HypeMC
209214
[@localheinz]: https://github.com/localheinz

src/Extension.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,15 @@
1818
use PHPUnit\Util;
1919

2020
try {
21-
$phpUnitVersion = Version\Version::fromString(Runner\Version::id());
21+
$phpUnitVersionSeries = Version\Series::fromString(Runner\Version::series());
2222
} catch (\InvalidArgumentException $exception) {
2323
throw new \RuntimeException(\sprintf(
24-
'Unable to determine PHPUnit version from version identifier "%s".',
25-
Runner\Version::id(),
24+
'Unable to determine PHPUnit version from version series "%s".',
25+
Runner\Version::series(),
2626
));
2727
}
2828

29-
if ($phpUnitVersion->major()->equals(Version\Major::fromInt(9))) {
29+
if ($phpUnitVersionSeries->major()->equals(Version\Major::fromInt(9))) {
3030
/**
3131
* @internal
3232
*/
@@ -170,7 +170,7 @@ private function resolveMaximumDuration(string $test): Duration
170170
return;
171171
}
172172

173-
if ($phpUnitVersion->major()->equals(Version\Major::fromInt(10))) {
173+
if ($phpUnitVersionSeries->major()->equals(Version\Major::fromInt(10))) {
174174
/**
175175
* @internal
176176
*/
@@ -224,6 +224,6 @@ public function bootstrap(
224224
}
225225

226226
throw new \RuntimeException(\sprintf(
227-
'Unable to select extension for PHPUnit version with version identifier "%s".',
228-
Runner\Version::id(),
227+
'Unable to select extension for PHPUnit version with version series "%s".',
228+
Runner\Version::series(),
229229
));

src/Version/Minor.php

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/Version/Patch.php

Lines changed: 0 additions & 47 deletions
This file was deleted.

src/Version/Series.php

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* Copyright (c) 2021-2023 Andreas Möller
7+
*
8+
* For the full copyright and license information, please view
9+
* the LICENSE.md file that was distributed with this source code.
10+
*
11+
* @see https://github.com/ergebnis/phpunit-slow-test-detector
12+
*/
13+
14+
namespace Ergebnis\PHPUnit\SlowTestDetector\Version;
15+
16+
/**
17+
* @internal
18+
*/
19+
final class Series
20+
{
21+
private Major $major;
22+
23+
private function __construct(Major $major)
24+
{
25+
$this->major = $major;
26+
}
27+
28+
public static function create(Major $major): self
29+
{
30+
return new self($major);
31+
}
32+
33+
/**
34+
* @throws \InvalidArgumentException
35+
*/
36+
public static function fromString(string $value): self
37+
{
38+
if (0 === \preg_match('/^(?P<major>(0|[1-9]\d*))\.(?P<minor>(0|[1-9]\d*))?$/', $value, $matches)) {
39+
throw new \InvalidArgumentException(\sprintf(
40+
'Value "%s" does not appear to be a valid value for a semantic version.',
41+
$value,
42+
));
43+
}
44+
45+
$major = Major::fromInt((int) $matches['major']);
46+
47+
return self::create($major);
48+
}
49+
50+
public function major(): Major
51+
{
52+
return $this->major;
53+
}
54+
}

src/Version/Version.php

Lines changed: 0 additions & 183 deletions
This file was deleted.

0 commit comments

Comments
 (0)