Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect PHPUnit version based on series instead of identifier #393

Merged
merged 1 commit into from
Dec 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
}

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