|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Hypernode\Deploy\Tests\Unit\Deployer\Task\Build; |
| 6 | + |
| 7 | +use Hypernode\Deploy\Deployer\Task\Build\HighPerformanceStaticDeployTask; |
| 8 | +use Hypernode\DeployConfiguration\Configuration; |
| 9 | +use PHPUnit\Framework\TestCase; |
| 10 | + |
| 11 | +class HighPerformanceStaticDeployTaskTest extends TestCase |
| 12 | +{ |
| 13 | + private HighPerformanceStaticDeployTask $task; |
| 14 | + |
| 15 | + protected function setUp(): void |
| 16 | + { |
| 17 | + $this->task = new HighPerformanceStaticDeployTask(); |
| 18 | + } |
| 19 | + |
| 20 | + public function testIsEnabledReturnsFalseWhenNotConfigured(): void |
| 21 | + { |
| 22 | + $config = $this->createMock(Configuration::class); |
| 23 | + $config->method('getVariables')->willReturn([]); |
| 24 | + |
| 25 | + $this->assertFalse($this->task->isEnabled($config)); |
| 26 | + } |
| 27 | + |
| 28 | + public function testIsEnabledReturnsTrueWhenEnabledInVariables(): void |
| 29 | + { |
| 30 | + $config = $this->createMock(Configuration::class); |
| 31 | + $config->method('getVariables') |
| 32 | + ->willReturnCallback(fn(string $stage = 'all') => match ($stage) { |
| 33 | + 'all' => ['high_performance_static_deploy' => true], |
| 34 | + default => [], |
| 35 | + }); |
| 36 | + |
| 37 | + $this->assertTrue($this->task->isEnabled($config)); |
| 38 | + } |
| 39 | + |
| 40 | + public function testIsEnabledReturnsTrueWhenEnabledInBuildVariables(): void |
| 41 | + { |
| 42 | + $config = $this->createMock(Configuration::class); |
| 43 | + $config->method('getVariables') |
| 44 | + ->willReturnCallback(fn(string $stage = 'all') => match ($stage) { |
| 45 | + 'build' => ['high_performance_static_deploy' => true], |
| 46 | + default => [], |
| 47 | + }); |
| 48 | + |
| 49 | + $this->assertTrue($this->task->isEnabled($config)); |
| 50 | + } |
| 51 | + |
| 52 | + public function testIsEnabledReturnsFalseWhenExplicitlyDisabled(): void |
| 53 | + { |
| 54 | + $config = $this->createMock(Configuration::class); |
| 55 | + $config->method('getVariables') |
| 56 | + ->willReturnCallback(fn(string $stage = 'all') => match ($stage) { |
| 57 | + 'all' => ['high_performance_static_deploy' => false], |
| 58 | + default => [], |
| 59 | + }); |
| 60 | + |
| 61 | + $this->assertFalse($this->task->isEnabled($config)); |
| 62 | + } |
| 63 | + |
| 64 | + public function testGetVersionReturnsDefaultWhenNotConfigured(): void |
| 65 | + { |
| 66 | + $config = $this->createMock(Configuration::class); |
| 67 | + $config->method('getVariables')->willReturn([]); |
| 68 | + |
| 69 | + $this->assertSame('latest', $this->task->getVersion($config)); |
| 70 | + } |
| 71 | + |
| 72 | + public function testGetVersionReturnsConfiguredVersion(): void |
| 73 | + { |
| 74 | + $config = $this->createMock(Configuration::class); |
| 75 | + $config->method('getVariables') |
| 76 | + ->willReturnCallback(fn(string $stage = 'all') => match ($stage) { |
| 77 | + 'all' => ['high_performance_static_deploy_version' => '1.0.0'], |
| 78 | + default => [], |
| 79 | + }); |
| 80 | + |
| 81 | + $this->assertSame('1.0.0', $this->task->getVersion($config)); |
| 82 | + } |
| 83 | + |
| 84 | + public function testGetVersionReturnsBuildVersionWhenNotInAllVariables(): void |
| 85 | + { |
| 86 | + $config = $this->createMock(Configuration::class); |
| 87 | + $config->method('getVariables') |
| 88 | + ->willReturnCallback(fn(string $stage = 'all') => match ($stage) { |
| 89 | + 'build' => ['high_performance_static_deploy_version' => '2.0.0'], |
| 90 | + default => [], |
| 91 | + }); |
| 92 | + |
| 93 | + $this->assertSame('2.0.0', $this->task->getVersion($config)); |
| 94 | + } |
| 95 | + |
| 96 | + public function testGetBinaryUrlReturnsLatestUrl(): void |
| 97 | + { |
| 98 | + $result = $this->task->getBinaryUrl('latest'); |
| 99 | + |
| 100 | + $this->assertSame( |
| 101 | + 'https://github.com/elgentos/magento2-static-deploy/releases/latest/download/magento2-static-deploy-linux-amd64', |
| 102 | + $result |
| 103 | + ); |
| 104 | + } |
| 105 | + |
| 106 | + public function testGetBinaryUrlReturnsVersionedUrl(): void |
| 107 | + { |
| 108 | + $result = $this->task->getBinaryUrl('0.0.8'); |
| 109 | + |
| 110 | + $this->assertSame( |
| 111 | + 'https://github.com/elgentos/magento2-static-deploy/releases/download/0.0.8/magento2-static-deploy-linux-amd64', |
| 112 | + $result |
| 113 | + ); |
| 114 | + } |
| 115 | + |
| 116 | + public function testGetBinaryUrlWithDifferentVersion(): void |
| 117 | + { |
| 118 | + $result = $this->task->getBinaryUrl('1.2.3'); |
| 119 | + |
| 120 | + $this->assertStringContainsString('1.2.3', $result); |
| 121 | + $this->assertStringContainsString('magento2-static-deploy-linux-amd64', $result); |
| 122 | + } |
| 123 | + |
| 124 | + public function testBuildThemeArgsWithSingleTheme(): void |
| 125 | + { |
| 126 | + $themes = ['Vendor/theme' => 'nl_NL en_US']; |
| 127 | + |
| 128 | + $result = $this->task->buildThemeArgs($themes); |
| 129 | + |
| 130 | + $this->assertSame('--theme=Vendor/theme', $result); |
| 131 | + } |
| 132 | + |
| 133 | + public function testBuildThemeArgsWithMultipleThemes(): void |
| 134 | + { |
| 135 | + $themes = [ |
| 136 | + 'Vendor/theme1' => 'nl_NL', |
| 137 | + 'Vendor/theme2' => 'en_US', |
| 138 | + 'Vendor/theme3' => 'de_DE', |
| 139 | + ]; |
| 140 | + |
| 141 | + $result = $this->task->buildThemeArgs($themes); |
| 142 | + |
| 143 | + $this->assertSame('--theme=Vendor/theme1 --theme=Vendor/theme2 --theme=Vendor/theme3', $result); |
| 144 | + } |
| 145 | + |
| 146 | + public function testBuildThemeArgsWithEmptyArray(): void |
| 147 | + { |
| 148 | + $result = $this->task->buildThemeArgs([]); |
| 149 | + |
| 150 | + $this->assertSame('', $result); |
| 151 | + } |
| 152 | +} |
0 commit comments