Skip to content

Commit 6e258bd

Browse files
author
Sven Jungnickel
committed
Fix download from a fallback url
1 parent c7aadd3 commit 6e258bd

File tree

7 files changed

+88
-148
lines changed

7 files changed

+88
-148
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
},
6666
"phpmd": {
6767
"url": "http://static.phpmd.org/php/latest/phpmd.phar",
68-
"fallback-url": "https://tooly.me-dresden.de/phpmd/2.6.0/phpmd.phar",
68+
"fallback-url": "https://github.com/jakzal/phpmd/releases/download/2.6.0-jakzal-2/phpmd.phar",
6969
"force-replace": true
7070
},
7171
"security-checker": {

src/Script/Decision/IsAccessibleDecision.php

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ class IsAccessibleDecision extends AbstractDecision
1717
public function canProceed(Tool $tool)
1818
{
1919
if (false === $this->helper->getDownloader()->isAccessible($tool->getUrl())) {
20-
return false;
20+
return $this->fallbackUrlIsAccessible($tool);
2121
}
2222

2323
if (empty($tool->getSignUrl())) {
@@ -38,4 +38,16 @@ public function getReason()
3838
{
3939
return '<error>At least one given URL are not accessible!</error>';
4040
}
41+
42+
/**
43+
* @param Tool $tool
44+
*
45+
* @return bool
46+
*/
47+
private function fallbackUrlIsAccessible(Tool $tool)
48+
{
49+
$fallbackUrl = $tool->getFallbackUrl();
50+
51+
return false === empty($fallbackUrl) && true === $this->helper->getDownloader()->isAccessible($fallbackUrl);
52+
}
4153
}

src/Script/Decision/UseFallbackURLDecision.php

Lines changed: 0 additions & 41 deletions
This file was deleted.

src/Script/Processor.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Tooly\Script\Decision\IsAccessibleDecision;
1010
use Tooly\Script\Decision\IsVerifiedDecision;
1111
use Tooly\Script\Decision\OnlyDevDecision;
12-
use Tooly\Script\Decision\UseFallbackURLDecision;
1312
use Tooly\Model\Tool;
1413

1514
/**
@@ -124,7 +123,6 @@ private function getDecisions()
124123
return [
125124
new OnlyDevDecision($this->configuration, $this->helper),
126125
new IsAccessibleDecision($this->configuration, $this->helper),
127-
new UseFallbackURLDecision($this->configuration, $this->helper),
128126
new FileAlreadyExistDecision($this->configuration, $this->helper),
129127
new IsVerifiedDecision($this->configuration, $this->helper),
130128
new DoReplaceDecision($this->configuration, $this->helper, $this->io),

tests/Script/Decision/IsAccessibleDecisionTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,28 @@ public function testNotAccessibleToolSignUrlReturnsFalse()
7474
])));
7575
}
7676

77+
public function testNotAccessibleToolUrlButAccessibleFallbackUrlReturnsTrue()
78+
{
79+
$downloader = $this
80+
->getMockBuilder(Downloader::class)
81+
->getMock();
82+
83+
$downloader
84+
->expects($this->exactly(2))
85+
->method('isAccessible')
86+
->will($this->onConsecutiveCalls(false, true));
87+
88+
$this->helper
89+
->expects($this->exactly(2))
90+
->method('getDownloader')
91+
->willReturn($downloader);
92+
93+
$decision = new IsAccessibleDecision($this->configuration, $this->helper);
94+
$this->assertTrue($decision->canProceed(ToolFactory::createTool('tool', __DIR__, [
95+
'fallback-url' => 'fallback-url'
96+
])));
97+
}
98+
7799
public function testAccessibleUrlsWillReturnTrue()
78100
{
79101
$downloader = $this

tests/Script/Decision/UseFallbackUrlDecisionTest.php

Lines changed: 0 additions & 103 deletions
This file was deleted.

tests/Script/Processor/ProcessTest.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,4 +121,56 @@ public function testCanSuccessfullyDownloadATool()
121121
$processor = new Processor($this->io, $this->helper, $this->configuration);
122122
$processor->process($tool);
123123
}
124+
125+
public function testCanSuccessfullyDownloadAToolViaFallbackUrl()
126+
{
127+
vfsStream::setup('bin');
128+
129+
$downloader = $this
130+
->getMockBuilder(Downloader::class)
131+
->getMock();
132+
133+
$downloader
134+
->expects($this->exactly(3))
135+
->method('isAccessible')
136+
->will($this->onConsecutiveCalls(false, true, false));
137+
138+
$filesystem = $this
139+
->getMockBuilder(Filesystem::class)
140+
->getMock();
141+
142+
$filesystem
143+
->method('isFileAlreadyExist')
144+
->willReturn(false);
145+
146+
$this->helper
147+
->method('getFilesystem')
148+
->willReturn($filesystem);
149+
150+
$this->helper
151+
->expects($this->exactly(4))
152+
->method('getDownloader')
153+
->willReturn($downloader);
154+
155+
$this->helper
156+
->method('isFileAlreadyExist')
157+
->willReturn(false);
158+
159+
$this->io
160+
->expects($this->exactly(2))
161+
->method('write');
162+
163+
$tool = $this
164+
->getMockBuilder(Tool::class)
165+
->disableOriginalConstructor()
166+
->getMock();
167+
168+
$tool
169+
->expects($this->exactly(2))
170+
->method('getFallbackUrl')
171+
->willReturn('//test.html');
172+
173+
$processor = new Processor($this->io, $this->helper, $this->configuration);
174+
$processor->process($tool);
175+
}
124176
}

0 commit comments

Comments
 (0)