deployer/test/recipe/DeployTest.php

94 lines
3.0 KiB
PHP
Raw Normal View History

2017-03-16 20:03:11 +07:00
<?php
/* (c) Anton Medvedev <anton@medv.io>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Deployer;
2017-03-19 18:15:02 +07:00
use Symfony\Component\Console\Output\OutputInterface;
2017-03-21 16:18:50 +07:00
use Symfony\Component\Process\Exception\ProcessFailedException;
2017-03-19 18:15:02 +07:00
2017-03-16 20:54:09 +07:00
class DeployTest extends DepCase
2017-03-16 20:03:11 +07:00
{
protected function load()
{
2017-03-21 16:23:41 +07:00
require DEPLOYER_FIXTURES . '/recipe/deploy.php';
2017-03-16 20:03:11 +07:00
}
protected function setUp()
{
self::$currentPath = self::$tmpPath . '/localhost';
}
2017-03-16 20:03:11 +07:00
public function testDeploy()
{
2017-03-21 16:18:50 +07:00
$output = $this->start('deploy', [], ['verbosity' => OutputInterface::VERBOSITY_DEBUG]);
2017-03-16 20:03:11 +07:00
self::assertContains('Successfully deployed!', $output);
self::assertDirectoryExists(self::$currentPath . '/.dep');
self::assertDirectoryExists(self::$currentPath . '/releases');
self::assertDirectoryExists(self::$currentPath . '/shared');
self::assertDirectoryExists(self::$currentPath . '/current');
self::assertFileExists(self::$currentPath . '/current/composer.json');
self::assertFileExists(self::$currentPath . '/shared/public/media/.gitkeep');
self::assertFileExists(self::$currentPath . '/shared/app/config/parameters.yml');
self::assertFileExists(self::$currentPath . '/shared/app/config/parameters_dev.yml');
self::assertFileExists(self::$currentPath . '/shared/app/config/parameters_prod.yml');
2017-03-16 20:03:11 +07:00
self::assertEquals(1, exec("ls -1 releases | wc -l"));
}
public function testKeepReleases()
{
2017-03-21 16:18:50 +07:00
$this->start('deploy');
$this->start('deploy');
$this->start('deploy');
$this->start('deploy');
2017-03-16 20:03:11 +07:00
2017-03-21 16:18:50 +07:00
$this->start('deploy');
2017-03-16 20:03:11 +07:00
exec('touch current/ok.txt');
2017-03-21 16:18:50 +07:00
$this->start('deploy');
2017-03-16 20:03:11 +07:00
exec('touch current/fail.txt');
2017-05-04 13:00:01 +07:00
self::assertEquals(5, exec("ls -1 releases | wc -l"));
2017-03-16 20:03:11 +07:00
2017-05-04 13:00:01 +07:00
// Make sure what after cleanup task same amount of releases a kept.
$this->start('cleanup');
2017-03-16 20:03:11 +07:00
self::assertEquals(5, exec("ls -1 releases | wc -l"));
}
/**
* @depends testKeepReleases
*/
public function testRollback()
{
2017-03-21 16:18:50 +07:00
$this->start('rollback');
2017-03-16 20:03:11 +07:00
self::assertEquals(4, exec("ls -1 releases | wc -l"));
self::assertFileExists(self::$currentPath . '/current/ok.txt');
self::assertFileNotExists(self::$currentPath . '/current/fail.txt');
2017-03-16 20:03:11 +07:00
}
2017-03-21 16:18:50 +07:00
/**
* @depends testRollback
*/
public function testFail()
{
self::expectException(ProcessFailedException::class);
$this->start('deploy_fail');
}
/**
* @depends testFail
*/
public function testAfterFail()
{
self::assertFileExists(self::$currentPath . '/current/ok.txt');
self::assertFileNotExists(self::$currentPath . '/.dep/deploy.lock');
2017-03-21 16:18:50 +07:00
$this->start('cleanup');
2017-05-04 13:00:01 +07:00
self::assertEquals(5, exec("ls -1 releases | wc -l"));
self::assertFileNotExists(self::$currentPath . '/release');
2017-03-21 16:18:50 +07:00
}
2017-03-16 20:03:11 +07:00
}