Skip to content
This repository has been archived by the owner on Apr 3, 2019. It is now read-only.

Commit

Permalink
Test that installer fails when release cannot be downloaded
Browse files Browse the repository at this point in the history
Fixes #108
  • Loading branch information
Reinier Kip committed Feb 22, 2017
1 parent 5a59535 commit c09cf70
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ The recommended way to install the QA Tools is by using our installer:

```
php -r "copy('https://raw.githubusercontent.com/ibuildingsnl/qa-tools/master/installer.php', 'qa-tools-setup.php');"
php -r "if (hash_file('SHA384', 'qa-tools-setup.php') === 'cbe46561b2dabe44c600f0ebdf262d73857c7e912bc4c891ee0a571f1df809b0c7881ee34ad13e598e606e35ea36c7f5') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('qa-tools-setup.php'); } echo PHP_EOL;"
php -r "if (hash_file('SHA384', 'qa-tools-setup.php') === '2f83e895f1fda9e44334f452e9abedfde9152ba1aa95d1ea411eef0d1c96086e8d8c68909ffeaa3ec7d72de420c85287') { echo 'Installer verified'; } else { echo 'Installer corrupt'; unlink('qa-tools-setup.php'); } echo PHP_EOL;"
php qa-tools-setup.php
php -r "unlink('qa-tools-setup.php');"
```
Expand Down
2 changes: 1 addition & 1 deletion installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ private function install($version)
}
}

return true;
return $success;
}

/**
Expand Down
35 changes: 29 additions & 6 deletions tests/integration/Installer/InstallerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Mockery;
use PharValidator;
use PHPUnit\Framework\TestCase;
use RuntimeException;
use Symfony\Component\Filesystem\Filesystem;

final class InstallerTest extends TestCase
Expand Down Expand Up @@ -73,9 +74,7 @@ public function tearDown()
$this->filesystem->remove($this->tempDirectory);
}

/**
* @test
*/
/** @test */
public function download_correct_files()
{
/** @var Mockery\Mock|HttpClient $httpClient */
Expand Down Expand Up @@ -118,18 +117,42 @@ public function download_correct_files()
$installer = new Installer(false, $httpClient, $pharValidator, self::REPOSITORY_OWNER, self::REPOSITORY_NAME);

ob_start();
$installer->run(false, $this->tempDirectory, 'qa-tools');
$success = $installer->run(false, $this->tempDirectory, 'qa-tools');
$output = ob_get_clean();

$this->assertTrue($success);
$this->assertRegExp(
'~^QA Tools \(version '.preg_quote(self::VERSION, '~').'\) successfully installed~sm',
$output
);

$this->assertFileExists($this->tempDirectory.'/qa-tools');
$this->assertEquals(self::PHAR_ASSET_CONTENTS, file_get_contents($this->tempDirectory.'/qa-tools'));

$this->assertFileExists($this->tempDirectory.'/qa-tools.pubkey');
$this->assertEquals(self::PUBKEY_ASSET_CONTENTS, file_get_contents($this->tempDirectory.'/qa-tools.pubkey'));
}

/** @test */
public function fails_when_files_cannot_be_downloaded()
{
/** @var Mockery\Mock|HttpClient $httpClient */
$httpClient = Mockery::mock(HttpClient::class);
$httpClient->shouldReceive('get')->andThrow(new RuntimeException());

/** @var Mockery\Mock|PharValidator $pharValidator */
$pharValidator = Mockery::mock(PharValidator::class);
$pharValidator->shouldReceive('assertPharValid');

$installer = new Installer(false, $httpClient, $pharValidator, self::REPOSITORY_OWNER, self::REPOSITORY_NAME);

ob_start();
$success = $installer->run(false, $this->tempDirectory, 'qa-tools');
$output = ob_get_clean();

$this->assertFalse($success);
$this->assertContains('Unable to download version information from https://', $output);
$this->assertContains('The download failed repeatedly, aborting.', $output);

$this->assertFileNotExists($this->tempDirectory.'/qa-tools');
$this->assertFileNotExists($this->tempDirectory.'/qa-tools.pubkey');
}
}

0 comments on commit c09cf70

Please sign in to comment.