Skip to content

Commit

Permalink
Merge pull request #393 from ergebnis/fix/simplify
Browse files Browse the repository at this point in the history
Detect PHPUnit version based on series instead of identifier
  • Loading branch information
localheinz authored Dec 3, 2023
2 parents 7b69bc5 + 1d4934f commit 34574df
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());
} 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(),
));
}

if ($phpUnitVersion->major()->equals(Version\Major::fromInt(9))) {
if ($phpUnitVersionSeries->major()->equals(Version\Major::fromInt(9))) {
/**
* @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))) {
/**
* @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(),
));
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 34574df

Please sign in to comment.