Skip to content

Commit

Permalink
Merge pull request #18 from svenjungnickel/fallback-url
Browse files Browse the repository at this point in the history
 Fix checksum of not accessible url using fall back url
  • Loading branch information
tommy-muehle authored Jun 24, 2019
2 parents dbc5778 + 8d0f4bf commit 0f2d81f
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 6 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,13 @@ You can add the requirement with this command:
This check often fails if you dont has the public key from the tool author
in your GPG keychain.

### fallback-url (optional, default none)

This option is useful if you want to add an extra layer of stability to your daily build processes.

In case the required url is not accessible and a `fallback-url` is set, tooly uses the fallback url to download the phar file.
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.

### force-replace (optional, default false)

Every time you update or install with composer the phar tools are checked. You are asked if you want to overwrite
Expand Down
8 changes: 7 additions & 1 deletion src/Script/Decision/FileAlreadyExistDecision.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ class FileAlreadyExistDecision extends AbstractDecision
*/
public function canProceed(Tool $tool)
{
if (false === $this->helper->isFileAlreadyExist($tool->getFilename(), $tool->getUrl())) {
$url = $tool->getUrl();

if (false === $this->helper->getDownloader()->isAccessible($url)) {
$url = $tool->getFallbackUrl();
}

if (false === $this->helper->isFileAlreadyExist($tool->getFilename(), $url)) {
return true;
}

Expand Down
98 changes: 95 additions & 3 deletions tests/Script/Decision/FileAlreadyExistDecisionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,63 @@

namespace Tooly\Tests\Script\Decision;

use Tooly\Factory\ToolFactory;
use Tooly\Model\Tool;
use Tooly\Script\Decision\FileAlreadyExistDecision;
use Tooly\Script\Helper\Downloader;

/**
* @package Tooly\Tests\Script\Decision
*/
class FileAlreadyExistDecisionTest extends DecisionTestCase
{
public function testIfFileNotAlreadyExistReturnsTrue()
public function testIfFileIsAccessibleAndFileNotAlreadyExistReturnsTrue()
{
$downloader = $this
->getMockBuilder(Downloader::class)
->disableOriginalConstructor()
->getMock();

$downloader
->expects($this->once())
->method('isAccessible')
->willReturn(true);

$this->helper
->expects($this->once())
->method('getDownloader')
->willReturn($downloader);

$this->helper
->expects($this->once())
->method('isFileAlreadyExist')
->willReturn(false);

$tool = $this
->getMockBuilder(Tool::class)
->disableOriginalConstructor()
->getMock();

$decision = new FileAlreadyExistDecision($this->configuration, $this->helper);
$this->assertTrue($decision->canProceed($tool));
}

public function testIfFileNotAccessibleAndFileNotAlreadyExistReturnsTrue()
{
$downloader = $this
->getMockBuilder(Downloader::class)
->disableOriginalConstructor()
->getMock();

$downloader
->expects($this->once())
->method('isAccessible')
->willReturn(false);

$this->helper
->expects($this->once())
->method('getDownloader')
->willReturn($downloader);

$this->helper
->expects($this->once())
->method('isFileAlreadyExist')
Expand All @@ -27,8 +73,54 @@ public function testIfFileNotAlreadyExistReturnsTrue()
$this->assertTrue($decision->canProceed($tool));
}

public function testIfFileAlreadyExistReturnsFalse()
public function testIfFileIsAccessibleAndFileAlreadyExistReturnsFalse()
{
$downloader = $this
->getMockBuilder(Downloader::class)
->disableOriginalConstructor()
->getMock();

$downloader
->expects($this->once())
->method('isAccessible')
->willReturn(true);

$this->helper
->expects($this->once())
->method('getDownloader')
->willReturn($downloader);

$this->helper
->expects($this->once())
->method('isFileAlreadyExist')
->willReturn(true);

$tool = $this
->getMockBuilder(Tool::class)
->disableOriginalConstructor()
->getMock();

$decision = new FileAlreadyExistDecision($this->configuration, $this->helper);
$this->assertFalse($decision->canProceed($tool));
}

public function testIfFileNotAccessibleAndFileAlreadyExistReturnsFalse()
{
$downloader = $this
->getMockBuilder(Downloader::class)
->disableOriginalConstructor()
->getMock();

$downloader
->expects($this->once())
->method('isAccessible')
->willReturn(false);

$this->helper
->expects($this->once())
->method('getDownloader')
->willReturn($downloader);

$this->helper
->expects($this->once())
->method('isFileAlreadyExist')
Expand Down
4 changes: 2 additions & 2 deletions tests/Script/Processor/ProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function testCanSuccessfullyDownloadAToolViaFallbackUrl()
->getMock();

$downloader
->expects($this->exactly(3))
->expects($this->exactly(4))
->method('isAccessible')
->will($this->onConsecutiveCalls(false, true, false));

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

$this->helper
->expects($this->exactly(4))
->expects($this->exactly(5))
->method('getDownloader')
->willReturn($downloader);

Expand Down

0 comments on commit 0f2d81f

Please sign in to comment.