|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Tests\Feature\Releases; |
| 6 | + |
| 7 | +use http\Exception\InvalidArgumentException; |
| 8 | +use Mockery; |
| 9 | +use TypistTech\PhpMatrix\Matrix; |
| 10 | +use TypistTech\PhpMatrix\MatrixInterface; |
| 11 | +use TypistTech\PhpMatrix\ReleasesInterface; |
| 12 | +use TypistTech\PhpMatrix\Versions; |
| 13 | +use UnexpectedValueException; |
| 14 | + |
| 15 | +covers(Versions::class); |
| 16 | + |
| 17 | +describe(Versions::class, static function (): void { |
| 18 | + describe('::sort()', static function (): void { |
| 19 | + dataset('sort', [ |
| 20 | + [['1.2.3']], |
| 21 | + [['1.2.3', '1.2.3']], |
| 22 | + [['1.2.3', '2.2.3']], |
| 23 | + [['1.2.3', '2.2.3', '3.2.3']], |
| 24 | + |
| 25 | + [['1.2']], |
| 26 | + [['1.2', '1.2']], |
| 27 | + [['1.2', '2.2']], |
| 28 | + [['1.2', '2.2', '3.2']], |
| 29 | + ]); |
| 30 | + |
| 31 | + it('sorts the versions', function (array $versions): void { |
| 32 | + $expected = $versions; |
| 33 | + |
| 34 | + shuffle($versions); |
| 35 | + |
| 36 | + $actual = Versions::sort(...$versions); |
| 37 | + |
| 38 | + expect($actual)->toBe($expected); |
| 39 | + } |
| 40 | + )->with('sort'); |
| 41 | + |
| 42 | + it('throws exception when argument is empty', function (): void { |
| 43 | + Versions::sort(); |
| 44 | + })->throws(UnexpectedValueException::class); |
| 45 | + }); |
| 46 | + |
| 47 | + describe('::lowest()', static function (): void { |
| 48 | + dataset('lowest', [ |
| 49 | + [['1.2.3'], '1.2.3'], |
| 50 | + [['1.2.3', '1.2.3'], '1.2.3'], |
| 51 | + [['1.2.3', '2.2.3'], '1.2.3'], |
| 52 | + [['1.2.3', '2.2.3', '3.2.3'], '1.2.3'], |
| 53 | + |
| 54 | + [['1.2'], '1.2'], |
| 55 | + [['1.2', '1.2'], '1.2'], |
| 56 | + [['1.2', '2.2'], '1.2'], |
| 57 | + [['1.2', '2.2', '3.2'], '1.2'], |
| 58 | + ]); |
| 59 | + |
| 60 | + it('returns the lowest version', function (array $versions, string $expected): void { |
| 61 | + shuffle($versions); |
| 62 | + |
| 63 | + $actual = Versions::lowest(...$versions); |
| 64 | + |
| 65 | + expect($actual)->toBe($expected); |
| 66 | + } |
| 67 | + )->with('lowest'); |
| 68 | + |
| 69 | + it('throws exception when argument is empty', function (): void { |
| 70 | + Versions::lowest(); |
| 71 | + })->throws(UnexpectedValueException::class); |
| 72 | + }); |
| 73 | + |
| 74 | + describe('::highest()', static function (): void { |
| 75 | + dataset('highest', [ |
| 76 | + [['1.2.3'], '1.2.3'], |
| 77 | + [['1.2.3', '1.2.3'], '1.2.3'], |
| 78 | + [['1.2.3', '2.2.3'], '2.2.3'], |
| 79 | + [['1.2.3', '2.2.3', '3.2.3'], '3.2.3'], |
| 80 | + |
| 81 | + [['1.2'], '1.2'], |
| 82 | + [['1.2', '1.2'], '1.2'], |
| 83 | + [['1.2', '2.2'], '2.2'], |
| 84 | + [['1.2', '2.2', '3.2'], '3.2'], |
| 85 | + ]); |
| 86 | + |
| 87 | + it('return the highest version', function (array $versions, string $expected): void { |
| 88 | + shuffle($versions); |
| 89 | + |
| 90 | + $actual = Versions::highest(...$versions); |
| 91 | + |
| 92 | + expect($actual)->toBe($expected); |
| 93 | + } |
| 94 | + )->with('highest'); |
| 95 | + |
| 96 | + it('throws exception when argument is empty', function (): void { |
| 97 | + Versions::highest(); |
| 98 | + })->throws(UnexpectedValueException::class); |
| 99 | + }); |
| 100 | +}); |
0 commit comments