generated from ergebnis/php-package-template
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
002c786
commit 421ce5b
Showing
10 changed files
with
310 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,9 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<files psalm-version="5.18.0@b113f3ed0259fd6e212d87c3df80eec95a6abf19"/> | ||
<files psalm-version="5.18.0@b113f3ed0259fd6e212d87c3df80eec95a6abf19"> | ||
<file src="test/Unit/VersionTest.php"> | ||
<PossiblyUnusedMethod> | ||
<code>provideInvalidValue</code> | ||
<code>provideValidValue</code> | ||
</PossiblyUnusedMethod> | ||
</file> | ||
</files> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 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/version | ||
*/ | ||
|
||
namespace Ergebnis\Version; | ||
|
||
final class Version | ||
{ | ||
/** | ||
* @see https://semver.org/#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string | ||
* @see https://regex101.com/r/Ly7O1x/3/ | ||
*/ | ||
private const REGEX = '/^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/'; | ||
|
||
private function __construct(private readonly string $value) | ||
{ | ||
} | ||
|
||
/** | ||
* @throws Exception\InvalidVersion | ||
*/ | ||
public static function fromString(string $value): self | ||
{ | ||
if (1 !== \preg_match(self::REGEX, $value)) { | ||
throw Exception\InvalidVersion::fromString($value); | ||
} | ||
|
||
return new self($value); | ||
} | ||
|
||
public function toString(): string | ||
{ | ||
return $this->value; | ||
} | ||
|
||
public function equals(self $other): bool | ||
{ | ||
return $this->value === $other->value; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* Copyright (c) 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/version | ||
*/ | ||
|
||
namespace Ergebnis\Version\Test\Unit\Exception; | ||
|
||
use Ergebnis\Version\Exception; | ||
use Ergebnis\Version\Test; | ||
use PHPUnit\Framework; | ||
|
||
#[Framework\Attributes\CoversClass(Exception\InvalidVersion::class)] | ||
final class InvalidVersionTest extends Framework\TestCase | ||
{ | ||
use Test\Util\Helper; | ||
|
||
public function testFromStringReturnsException(): void | ||
{ | ||
$value = self::faker()->word(); | ||
|
||
$exception = Exception\InvalidVersion::fromString($value); | ||
|
||
$message = \sprintf( | ||
'Value "%s" does not appear to be valid.', | ||
$value, | ||
); | ||
|
||
self::assertSame($message, $exception->getMessage()); | ||
} | ||
} |
Oops, something went wrong.