Skip to content

Commit

Permalink
Fix: Detect PHPUnit version based on series instead of identifier
Browse files Browse the repository at this point in the history
Co-authored-by: Andreas Möller <[email protected]>
Co-authored-by: Michael Voříšek <[email protected]>
  • Loading branch information
localheinz and mvorisek committed Dec 3, 2023
1 parent 7b69bc5 commit 1d4934f
Show file tree
Hide file tree
Showing 10 changed files with 272 additions and 847 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ For a full diff see [`2.4.0...main`][2.4.0...main].
- Added support for PHP 8.0 ([#375]), by [@localheinz] and [@mvorisek]
- Added support for PHP 7.4 ([#390]), by [@localheinz] and [@mvorisek]

### Changed

- Improved detection of PHPUnit version ([#393]), by [@localheinz] and [@mvorisek]

## [`2.4.0`][2.4.0]

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

[@HypeMC]: https://github.com/HypeMC
[@localheinz]: https://github.com/localheinz
Expand Down
14 changes: 7 additions & 7 deletions src/Extension.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
use PHPUnit\Util;

try {
$phpUnitVersion = Version\Version::fromString(Runner\Version::id());
$phpUnitVersionSeries = Version\Series::fromString(Runner\Version::series());

Check warning on line 21 in src/Extension.php

View check run for this annotation

Codecov / codecov/patch

src/Extension.php#L21

Added line #L21 was not covered by tests
} catch (\InvalidArgumentException $exception) {
throw new \RuntimeException(\sprintf(
'Unable to determine PHPUnit version from version identifier "%s".',
Runner\Version::id(),
'Unable to determine PHPUnit version from version series "%s".',
Runner\Version::series(),

Check warning on line 25 in src/Extension.php

View check run for this annotation

Codecov / codecov/patch

src/Extension.php#L24-L25

Added lines #L24 - L25 were not covered by tests
));
}

if ($phpUnitVersion->major()->equals(Version\Major::fromInt(9))) {
if ($phpUnitVersionSeries->major()->equals(Version\Major::fromInt(9))) {

Check warning on line 29 in src/Extension.php

View check run for this annotation

Codecov / codecov/patch

src/Extension.php#L29

Added line #L29 was not covered by tests
/**
* @internal
*/
Expand Down Expand Up @@ -170,7 +170,7 @@ private function resolveMaximumDuration(string $test): Duration
return;
}

if ($phpUnitVersion->major()->equals(Version\Major::fromInt(10))) {
if ($phpUnitVersionSeries->major()->equals(Version\Major::fromInt(10))) {

Check warning on line 173 in src/Extension.php

View check run for this annotation

Codecov / codecov/patch

src/Extension.php#L173

Added line #L173 was not covered by tests
/**
* @internal
*/
Expand Down Expand Up @@ -224,6 +224,6 @@ public function bootstrap(
}

throw new \RuntimeException(\sprintf(
'Unable to select extension for PHPUnit version with version identifier "%s".',
Runner\Version::id(),
'Unable to select extension for PHPUnit version with version series "%s".',
Runner\Version::series(),

Check warning on line 228 in src/Extension.php

View check run for this annotation

Codecov / codecov/patch

src/Extension.php#L227-L228

Added lines #L227 - L228 were not covered by tests
));
47 changes: 0 additions & 47 deletions src/Version/Minor.php

This file was deleted.

47 changes: 0 additions & 47 deletions src/Version/Patch.php

This file was deleted.

54 changes: 54 additions & 0 deletions src/Version/Series.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

/**
* Copyright (c) 2021-2023 Andreas Möller
*
* For the full copyright and license information, please view
* the LICENSE.md file that was distributed with this source code.
*
* @see https://github.com/ergebnis/phpunit-slow-test-detector
*/

namespace Ergebnis\PHPUnit\SlowTestDetector\Version;

/**
* @internal
*/
final class Series
{
private Major $major;

private function __construct(Major $major)
{
$this->major = $major;
}

public static function create(Major $major): self
{
return new self($major);
}

/**
* @throws \InvalidArgumentException
*/
public static function fromString(string $value): self
{
if (0 === \preg_match('/^(?P<major>(0|[1-9]\d*))\.(?P<minor>(0|[1-9]\d*))?$/', $value, $matches)) {
throw new \InvalidArgumentException(\sprintf(
'Value "%s" does not appear to be a valid value for a semantic version.',
$value,
));
}

$major = Major::fromInt((int) $matches['major']);

return self::create($major);
}

public function major(): Major
{
return $this->major;
}
}
183 changes: 0 additions & 183 deletions src/Version/Version.php

This file was deleted.

Loading

0 comments on commit 1d4934f

Please sign in to comment.