Skip to content

Commit

Permalink
ignore release patch number when checking php version
Browse files Browse the repository at this point in the history
  • Loading branch information
fain182 committed Jan 15, 2024
1 parent 5c51aea commit 0deda46
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
21 changes: 11 additions & 10 deletions src/CLI/TargetPhpVersion.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,22 +22,23 @@ class TargetPhpVersion
/** @var string|null */
private $version;

private function __construct(?string $version)
private function __construct(string $version)
{
$this->version = $version;
}

public static function create(?string $version): self
{
if (null === $version) {
return new self(phpversion());
$versionNumbers = explode('.', $version);
if (count($versionNumbers) == 3) {
$version = $versionNumbers[0].'.'.$versionNumbers[1];
}

if (!\in_array($version, (new self(null))::VALID_PHP_VERSIONS)) {
if (!\in_array($version, self::VALID_PHP_VERSIONS)) {
throw new PhpVersionNotValidException($version);
}

return new self($version);
$this->version = $version;
}

public static function create(?string $version): self
{
return new self($version ?? phpversion());
}

public function get(): ?string
Expand Down
7 changes: 7 additions & 0 deletions tests/Unit/CLI/TargetPhpVersionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ public function test_it_should_return_passed_php_version(): void
$this->assertEquals('8.3', $targetPhpVersion->get());
}

public function test_it_should_ignore_the_patch_number(): void
{
$targetPhpVersion = TargetPhpVersion::create('8.3.2');

$this->assertEquals('8.3', $targetPhpVersion->get());
}

public function test_it_should_throw_exception_if_not_valid_php_version(): void
{
$this->expectException(PhpVersionNotValidException::class);
Expand Down

0 comments on commit 0deda46

Please sign in to comment.