From 5eedf32a330c0fe19a965dd262e320caae9e5d89 Mon Sep 17 00:00:00 2001 From: Anton Medvedev Date: Sat, 14 Feb 2015 01:01:42 +0300 Subject: [PATCH] Refactor common.php and add test for recipes. --- phpunit.xml | 7 +-- recipe/common.php | 3 +- test/recipe/CommonTest.php | 92 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 98 insertions(+), 4 deletions(-) create mode 100644 test/recipe/CommonTest.php diff --git a/phpunit.xml b/phpunit.xml index a50960b7..b14dc01d 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -8,8 +8,9 @@ - - src/ - + + vendor/ + bin/ + diff --git a/recipe/common.php b/recipe/common.php index 73148c30..99cd8ff9 100644 --- a/recipe/common.php +++ b/recipe/common.php @@ -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'); diff --git a/test/recipe/CommonTest.php b/test/recipe/CommonTest.php new file mode 100644 index 00000000..03f6c633 --- /dev/null +++ b/test/recipe/CommonTest.php @@ -0,0 +1,92 @@ + + * + * 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)); + } + +}