Skip to content

Commit 0f2d81f

Browse files
authored
Merge pull request #18 from svenjungnickel/fallback-url
Fix checksum of not accessible url using fall back url
2 parents dbc5778 + 8d0f4bf commit 0f2d81f

File tree

4 files changed

+111
-6
lines changed

4 files changed

+111
-6
lines changed

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,13 @@ You can add the requirement with this command:
105105
This check often fails if you dont has the public key from the tool author
106106
in your GPG keychain.
107107

108+
### fallback-url (optional, default none)
109+
110+
This option is useful if you want to add an extra layer of stability to your daily build processes.
111+
112+
In case the required url is not accessible and a `fallback-url` is set, tooly uses the fallback url to download the phar file.
113+
The fallback url can be a link to a specific version, such as x.y.z, or a link to the latest version for this phar.
114+
108115
### force-replace (optional, default false)
109116

110117
Every time you update or install with composer the phar tools are checked. You are asked if you want to overwrite

src/Script/Decision/FileAlreadyExistDecision.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,13 @@ class FileAlreadyExistDecision extends AbstractDecision
1616
*/
1717
public function canProceed(Tool $tool)
1818
{
19-
if (false === $this->helper->isFileAlreadyExist($tool->getFilename(), $tool->getUrl())) {
19+
$url = $tool->getUrl();
20+
21+
if (false === $this->helper->getDownloader()->isAccessible($url)) {
22+
$url = $tool->getFallbackUrl();
23+
}
24+
25+
if (false === $this->helper->isFileAlreadyExist($tool->getFilename(), $url)) {
2026
return true;
2127
}
2228

tests/Script/Decision/FileAlreadyExistDecisionTest.php

Lines changed: 95 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,63 @@
22

33
namespace Tooly\Tests\Script\Decision;
44

5-
use Tooly\Factory\ToolFactory;
65
use Tooly\Model\Tool;
76
use Tooly\Script\Decision\FileAlreadyExistDecision;
7+
use Tooly\Script\Helper\Downloader;
88

99
/**
1010
* @package Tooly\Tests\Script\Decision
1111
*/
1212
class FileAlreadyExistDecisionTest extends DecisionTestCase
1313
{
14-
public function testIfFileNotAlreadyExistReturnsTrue()
14+
public function testIfFileIsAccessibleAndFileNotAlreadyExistReturnsTrue()
1515
{
16+
$downloader = $this
17+
->getMockBuilder(Downloader::class)
18+
->disableOriginalConstructor()
19+
->getMock();
20+
21+
$downloader
22+
->expects($this->once())
23+
->method('isAccessible')
24+
->willReturn(true);
25+
26+
$this->helper
27+
->expects($this->once())
28+
->method('getDownloader')
29+
->willReturn($downloader);
30+
31+
$this->helper
32+
->expects($this->once())
33+
->method('isFileAlreadyExist')
34+
->willReturn(false);
35+
36+
$tool = $this
37+
->getMockBuilder(Tool::class)
38+
->disableOriginalConstructor()
39+
->getMock();
40+
41+
$decision = new FileAlreadyExistDecision($this->configuration, $this->helper);
42+
$this->assertTrue($decision->canProceed($tool));
43+
}
44+
45+
public function testIfFileNotAccessibleAndFileNotAlreadyExistReturnsTrue()
46+
{
47+
$downloader = $this
48+
->getMockBuilder(Downloader::class)
49+
->disableOriginalConstructor()
50+
->getMock();
51+
52+
$downloader
53+
->expects($this->once())
54+
->method('isAccessible')
55+
->willReturn(false);
56+
57+
$this->helper
58+
->expects($this->once())
59+
->method('getDownloader')
60+
->willReturn($downloader);
61+
1662
$this->helper
1763
->expects($this->once())
1864
->method('isFileAlreadyExist')
@@ -27,8 +73,54 @@ public function testIfFileNotAlreadyExistReturnsTrue()
2773
$this->assertTrue($decision->canProceed($tool));
2874
}
2975

30-
public function testIfFileAlreadyExistReturnsFalse()
76+
public function testIfFileIsAccessibleAndFileAlreadyExistReturnsFalse()
3177
{
78+
$downloader = $this
79+
->getMockBuilder(Downloader::class)
80+
->disableOriginalConstructor()
81+
->getMock();
82+
83+
$downloader
84+
->expects($this->once())
85+
->method('isAccessible')
86+
->willReturn(true);
87+
88+
$this->helper
89+
->expects($this->once())
90+
->method('getDownloader')
91+
->willReturn($downloader);
92+
93+
$this->helper
94+
->expects($this->once())
95+
->method('isFileAlreadyExist')
96+
->willReturn(true);
97+
98+
$tool = $this
99+
->getMockBuilder(Tool::class)
100+
->disableOriginalConstructor()
101+
->getMock();
102+
103+
$decision = new FileAlreadyExistDecision($this->configuration, $this->helper);
104+
$this->assertFalse($decision->canProceed($tool));
105+
}
106+
107+
public function testIfFileNotAccessibleAndFileAlreadyExistReturnsFalse()
108+
{
109+
$downloader = $this
110+
->getMockBuilder(Downloader::class)
111+
->disableOriginalConstructor()
112+
->getMock();
113+
114+
$downloader
115+
->expects($this->once())
116+
->method('isAccessible')
117+
->willReturn(false);
118+
119+
$this->helper
120+
->expects($this->once())
121+
->method('getDownloader')
122+
->willReturn($downloader);
123+
32124
$this->helper
33125
->expects($this->once())
34126
->method('isFileAlreadyExist')

tests/Script/Processor/ProcessTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function testCanSuccessfullyDownloadAToolViaFallbackUrl()
131131
->getMock();
132132

133133
$downloader
134-
->expects($this->exactly(3))
134+
->expects($this->exactly(4))
135135
->method('isAccessible')
136136
->will($this->onConsecutiveCalls(false, true, false));
137137

@@ -148,7 +148,7 @@ public function testCanSuccessfullyDownloadAToolViaFallbackUrl()
148148
->willReturn($filesystem);
149149

150150
$this->helper
151-
->expects($this->exactly(4))
151+
->expects($this->exactly(5))
152152
->method('getDownloader')
153153
->willReturn($downloader);
154154

0 commit comments

Comments
 (0)