Skip to content

Commit 7e54d67

Browse files
committed
Cachetool: Update binary version mapping
1 parent bbe1ba7 commit 7e54d67

2 files changed

Lines changed: 106 additions & 13 deletions

File tree

src/Deployer/Task/After/CachetoolTask.php

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,16 @@ class CachetoolTask extends TaskBase
1919
/**
2020
* @var string[]
2121
*
22+
* CacheTool 9.x/10.x works with PHP >=8.1
2223
* CacheTool 8.x works with PHP >=8.0
2324
* CacheTool 7.x works with PHP >=7.3
2425
* CacheTool 6.x works with PHP >=7.3
2526
* CacheTool 5.x works with PHP >=7.2
2627
* CacheTool 4.x works with PHP >=7.1
2728
*/
2829
private $versionBinaryMapping = [
29-
8 => 'https://github.com/gordalina/cachetool/releases/download/8.4.0/cachetool.phar',
30+
10 => 'https://github.com/gordalina/cachetool/releases/download/10.0.0/cachetool.phar',
31+
8 => 'https://github.com/gordalina/cachetool/releases/download/8.6.1/cachetool.phar',
3032
7 => 'https://github.com/gordalina/cachetool/releases/download/7.1.0/cachetool.phar',
3133
6 => 'https://github.com/gordalina/cachetool/releases/download/6.6.0/cachetool.phar',
3234
5 => 'https://github.com/gordalina/cachetool/releases/download/5.1.3/cachetool.phar',
@@ -52,10 +54,10 @@ public function configure(Configuration $config): void
5254
$cachetoolBinary = get('cachetool_binary');
5355

5456
within('{{release_path}}', function () {
55-
run('curl -L -o cachetool.phar ' . $this->getCachetoolUrl());
57+
$phpVersion = $this->getPhpVersion();
5658
$cachetoolBinary = '{{release_path}}/cachetool.phar';
57-
58-
writeln(sprintf("Downloaded cachetool %s for PHP %f", $cachetoolBinary, $this->getPhpVersion()));
59+
run('curl -L -o cachetool.phar ' . $this->getCachetoolUrl($phpVersion));
60+
writeln(sprintf("Downloaded cachetool %s for PHP %s", $cachetoolBinary, $phpVersion));
5961
return $cachetoolBinary;
6062
});
6163
return $cachetoolBinary;
@@ -103,30 +105,36 @@ public function configure(Configuration $config): void
103105
});
104106
}
105107

106-
protected function getPhpVersion(): float
108+
protected function getPhpVersion(): string
107109
{
108-
return (float) run('{{bin/php}} -r "echo PHP_VERSION . \" - \" . PHP_VERSION_ID;"');
110+
return run('{{bin/php}} -r "echo PHP_VERSION;"');
109111
}
110112

111-
public function getCachetoolUrl(): string
113+
public function getCachetoolUrl(?string $phpVersion = null): string
112114
{
113-
$phpVersion = $this->getPhpVersion();
114-
if ($phpVersion >= 8.0) {
115+
$phpVersion = $phpVersion ?? $this->getPhpVersion();
116+
117+
if (version_compare($phpVersion, '8.1.0', '>=')) {
118+
return $this->versionBinaryMapping[10];
119+
}
120+
121+
if (version_compare($phpVersion, '8.0.0', '>=')) {
115122
return $this->versionBinaryMapping[8];
116123
}
117124

118-
if ($phpVersion >= 7.3) {
125+
if (version_compare($phpVersion, '7.3.0', '>=')) {
119126
return $this->versionBinaryMapping[7];
120127
}
121128

122-
if ($phpVersion >= 7.2) {
129+
if (version_compare($phpVersion, '7.2.0', '>=')) {
123130
return $this->versionBinaryMapping[5];
124131
}
125132

126-
if ($phpVersion >= 7.1) {
133+
if (version_compare($phpVersion, '7.1.0', '>=')) {
127134
return $this->versionBinaryMapping[4];
128135
}
129136

130-
return $this->versionBinaryMapping[8];
137+
// Default to latest for unknown/newer PHP versions
138+
return $this->versionBinaryMapping[10];
131139
}
132140
}
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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

Comments
 (0)