|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Hypernode\Deploy\Tests\Unit\Deployer\Task\After; |
| 6 | + |
| 7 | +use Hypernode\Deploy\Deployer\Task\After\CachetoolTask; |
| 8 | +use PHPUnit\Framework\TestCase; |
| 9 | + |
| 10 | +class CachetoolTaskTest extends TestCase |
| 11 | +{ |
| 12 | + private CachetoolTask $task; |
| 13 | + |
| 14 | + protected function setUp(): void |
| 15 | + { |
| 16 | + $this->task = new CachetoolTask(); |
| 17 | + } |
| 18 | + |
| 19 | + /** |
| 20 | + * @dataProvider phpVersionToCachetoolUrlProvider |
| 21 | + */ |
| 22 | + public function testGetCachetoolUrlReturnsCorrectVersionForPhpVersion( |
| 23 | + string $phpVersion, |
| 24 | + string $expectedUrlPart |
| 25 | + ): void { |
| 26 | + $result = $this->task->getCachetoolUrl($phpVersion); |
| 27 | + |
| 28 | + $this->assertStringContainsString($expectedUrlPart, $result); |
| 29 | + } |
| 30 | + |
| 31 | + /** |
| 32 | + * @return array<string, array{string, string}> |
| 33 | + */ |
| 34 | + public static function phpVersionToCachetoolUrlProvider(): array |
| 35 | + { |
| 36 | + return [ |
| 37 | + // PHP 8.1+ should get cachetool 10.x |
| 38 | + 'PHP 8.3.15 gets cachetool 10' => ['8.3.15', '10.0.0'], |
| 39 | + 'PHP 8.2.0 gets cachetool 10' => ['8.2.0', '10.0.0'], |
| 40 | + 'PHP 8.1.0 gets cachetool 10' => ['8.1.0', '10.0.0'], |
| 41 | + 'PHP 8.1.27 gets cachetool 10' => ['8.1.27', '10.0.0'], |
| 42 | + |
| 43 | + // PHP 8.0.x should get cachetool 8.x |
| 44 | + 'PHP 8.0.0 gets cachetool 8' => ['8.0.0', '8.6.1'], |
| 45 | + 'PHP 8.0.30 gets cachetool 8' => ['8.0.30', '8.6.1'], |
| 46 | + |
| 47 | + // PHP 7.3+ should get cachetool 7.x |
| 48 | + 'PHP 7.4.33 gets cachetool 7' => ['7.4.33', '7.1.0'], |
| 49 | + 'PHP 7.3.0 gets cachetool 7' => ['7.3.0', '7.1.0'], |
| 50 | + 'PHP 7.3.33 gets cachetool 7' => ['7.3.33', '7.1.0'], |
| 51 | + |
| 52 | + // PHP 7.2.x should get cachetool 5.x |
| 53 | + 'PHP 7.2.0 gets cachetool 5' => ['7.2.0', '5.1.3'], |
| 54 | + 'PHP 7.2.34 gets cachetool 5' => ['7.2.34', '5.1.3'], |
| 55 | + |
| 56 | + // PHP 7.1.x should get cachetool 4.x |
| 57 | + 'PHP 7.1.0 gets cachetool 4' => ['7.1.0', '4.1.1'], |
| 58 | + 'PHP 7.1.33 gets cachetool 4' => ['7.1.33', '4.1.1'], |
| 59 | + |
| 60 | + // Unsupported/old PHP versions fall back to latest (10.x) |
| 61 | + 'PHP 7.0.33 falls back to cachetool 10' => ['7.0.33', '10.0.0'], |
| 62 | + 'PHP 5.6.40 falls back to cachetool 10' => ['5.6.40', '10.0.0'], |
| 63 | + |
| 64 | + // Future PHP versions should get latest (10.x) |
| 65 | + 'PHP 9.0.0 gets cachetool 10' => ['9.0.0', '10.0.0'], |
| 66 | + 'PHP 8.4.0 gets cachetool 10' => ['8.4.0', '10.0.0'], |
| 67 | + ]; |
| 68 | + } |
| 69 | + |
| 70 | + public function testGetCachetoolUrlReturnsFullGithubUrl(): void |
| 71 | + { |
| 72 | + $result = $this->task->getCachetoolUrl('8.2.0'); |
| 73 | + |
| 74 | + $this->assertStringStartsWith('https://github.com/gordalina/cachetool/releases/download/', $result); |
| 75 | + $this->assertStringEndsWith('/cachetool.phar', $result); |
| 76 | + } |
| 77 | + |
| 78 | + public function testGetCachetoolUrlForPhp71ReturnsLegacyUrl(): void |
| 79 | + { |
| 80 | + $result = $this->task->getCachetoolUrl('7.1.0'); |
| 81 | + |
| 82 | + // Cachetool 4.x uses a different URL format (gordalina.github.io) |
| 83 | + $this->assertStringStartsWith('https://gordalina.github.io/cachetool/downloads/', $result); |
| 84 | + } |
| 85 | +} |
0 commit comments