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