-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #61 from siketyan/skip-unsupported-version
🩹 Skip the package with unknown version type
- Loading branch information
Showing
12 changed files
with
184 additions
and
43 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 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
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 |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Siketyan\Loxcan\Versioning\Unknown; | ||
|
||
use Siketyan\Loxcan\Versioning\VersionInterface; | ||
|
||
class UnknownVersion implements VersionInterface | ||
{ | ||
private string $version; | ||
|
||
public function __construct( | ||
string $version | ||
) { | ||
$this->version = $version; | ||
} | ||
|
||
public function __toString(): string | ||
{ | ||
return $this->version; | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Siketyan\Loxcan\Versioning\Unknown; | ||
|
||
use Siketyan\Loxcan\Versioning\VersionComparatorInterface; | ||
use Siketyan\Loxcan\Versioning\VersionDiff; | ||
use Siketyan\Loxcan\Versioning\VersionInterface; | ||
|
||
class UnknownVersionComparator implements VersionComparatorInterface | ||
{ | ||
public function compare(VersionInterface $before, VersionInterface $after): ?VersionDiff | ||
{ | ||
return new VersionDiff( | ||
VersionDiff::UNKNOWN, | ||
$before, | ||
$after, | ||
); | ||
} | ||
|
||
public function supports(string $beforeType, string $afterType): bool | ||
{ | ||
return is_a($beforeType, VersionInterface::class, true) | ||
&& is_a($afterType, VersionInterface::class, true) | ||
; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,76 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Siketyan\Loxcan\Versioning\Unknown; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Siketyan\Loxcan\Versioning\SemVer\SemVerVersion; | ||
use Siketyan\Loxcan\Versioning\Simple\SimpleVersion; | ||
use Siketyan\Loxcan\Versioning\VersionDiff; | ||
use Siketyan\Loxcan\Versioning\VersionInterface; | ||
|
||
class UnknownVersionComparatorTest extends TestCase | ||
{ | ||
private UnknownVersionComparator $comparator; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->comparator = new UnknownVersionComparator(); | ||
} | ||
|
||
public function test(): void | ||
{ | ||
$this->assertCompare( | ||
VersionDiff::UNKNOWN, | ||
new UnknownVersion('1.2.3.4'), | ||
new SimpleVersion(1, 2, 3, 4), | ||
); | ||
|
||
$this->assertCompare( | ||
VersionDiff::UNKNOWN, | ||
new UnknownVersion('1.2.3.4'), | ||
new UnknownVersion('2.3.4.5'), | ||
); | ||
|
||
$this->assertCompare( | ||
VersionDiff::UNKNOWN, | ||
new SimpleVersion(1, 2, 3, 4), | ||
new SimpleVersion(2, 3, 4, 5), | ||
); | ||
} | ||
|
||
public function testSupports(): void | ||
{ | ||
$this->assertTrue( | ||
$this->comparator->supports(UnknownVersion::class, UnknownVersion::class), | ||
); | ||
|
||
$this->assertTrue( | ||
$this->comparator->supports(SimpleVersion::class, UnknownVersion::class), | ||
); | ||
|
||
$this->assertTrue( | ||
$this->comparator->supports(SemVerVersion::class, SimpleVersion::class), | ||
); | ||
|
||
$this->assertFalse( | ||
$this->comparator->supports(UnknownVersion::class, VersionDiff::class), | ||
); | ||
} | ||
|
||
private function assertCompare(?int $type, VersionInterface $before, VersionInterface $after): void | ||
{ | ||
$diff = $this->comparator->compare($before, $after); | ||
|
||
if ($type === null) { | ||
$this->assertNull($diff); | ||
|
||
return; | ||
} | ||
|
||
$this->assertSame($type, $diff->getType()); | ||
$this->assertSame($before, $diff->getBefore()); | ||
$this->assertSame($after, $diff->getAfter()); | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Siketyan\Loxcan\Versioning\Unknown; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
|
||
class UnknownVersionTest extends TestCase | ||
{ | ||
private const VERSION = '1.2.3.4'; | ||
|
||
private UnknownVersion $version; | ||
|
||
protected function setUp(): void | ||
{ | ||
$this->version = new UnknownVersion(self::VERSION); | ||
} | ||
|
||
public function testToString(): void | ||
{ | ||
$this->assertSame( | ||
self::VERSION, | ||
$this->version->__toString(), | ||
); | ||
} | ||
} |