Refactor common.php and add test for recipes.

This commit is contained in:
Anton Medvedev 2015-02-14 01:01:42 +03:00
parent c7a60bd91f
commit 5eedf32a33
3 changed files with 98 additions and 4 deletions

View File

@ -8,8 +8,9 @@
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">src/</directory>
</whitelist>
<blacklist>
<directory suffix=".php">vendor/</directory>
<directory>bin/</directory>
</blacklist>
</filter>
</phpunit>

View File

@ -77,8 +77,9 @@ task('deploy:release', function () {
*/
task('deploy:update_code', function () {
$repository = get('repository');
run("git clone --recursive -q $repository {release_path}");
run("chmod -R g+w {release_path}");
})->desc('Updating code');

View File

@ -0,0 +1,92 @@
<?php
/* (c) Anton Medvedev <anton@elfet.ru>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Deployer;
use Deployer\Console\Application;
use Symfony\Component\Console\Tester\ApplicationTester;
class CommonTest extends \PHPUnit_Framework_TestCase
{
/**
* @var ApplicationTester
*/
private $tester;
/**
* @var Deployer
*/
private $deployer;
/**
* @var string
*/
private $deployPath;
public function __construct($name = null, array $data = array(), $dataName = '')
{
parent::__construct($name, $data, $dataName);
$input = $this->getMock('Symfony\Component\Console\Input\InputInterface');
$output = $this->getMock('Symfony\Component\Console\Output\OutputInterface');
$console = new Application();
$console->setAutoExit(false);
$console->setCatchExceptions(false);
$this->tester = new ApplicationTester($console);
$this->deployer = new \Deployer\Deployer($console, $input, $output);
$this->deployPath = __DIR__ . '/local';
if (is_dir($this->deployPath)) {
exec("rm -rf $this->deployPath");
}
mkdir($this->deployPath);
require __DIR__ . '/../../recipe/common.php';
localServer('test')
->env('deploy_path', $this->deployPath);
$this->deployer->addConsoleCommands();
}
public static function tearDownAfterClass()
{
if (is_dir(__DIR__ . '/local')) {
exec("rm -rf " . __DIR__ . '/local');
}
}
public function testPrepare()
{
$this->tester->run(['command' => 'deploy:prepare']);
$this->assertFileExists($this->deployPath . '/releases');
$this->assertFileExists($this->deployPath . '/shared');
}
public function testRelease()
{
$this->tester->run(['command' => 'deploy:release']);
$this->assertFileExists($this->deployPath . '/release');
$this->assertFileExists($deployPath = readlink($this->deployPath . '/release'));
$this->assertEquals(1, basename($deployPath));
}
public function testReleaseSecond()
{
$this->tester->run(['command' => 'deploy:release']);
$this->assertFileExists($deployPath = readlink($this->deployPath . '/release'));
$this->assertEquals(2, basename($deployPath));
}
}