[Nostromo] Improve tests and coverage

This commit is contained in:
Andrés Montañez 2017-01-04 22:21:38 -03:00
parent b56e1c378c
commit f4f8bfbf05
5 changed files with 98 additions and 6 deletions

View file

@ -39,10 +39,11 @@ class DeployCommandMiscTest extends TestCase
3 => 'composer install',
4 => 'composer dumpautoload --optimize',
5 => 'rsync -e "ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no" -avz --exclude=.git --exclude=./var/cache/* --exclude=./var/log/* --exclude=./web/app_dev.php ./ tester@testhost:/var/www/test',
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& sudo bin/console cache:warmup --env=dev \\"',
7 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& sudo bin/console assets:install --env=dev --symlink --relative web\\"',
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& sudo bin/console assetic:dump --env=dev \\"',
9 => 'git checkout master',
6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& sudo bin/console cache:clear --env=dev \\"',
7 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& sudo bin/console cache:warmup --env=dev \\"',
8 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& sudo bin/console assets:install --env=dev --symlink --relative web\\"',
9 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& sudo bin/console assetic:dump --env=dev \\"',
10 => 'git checkout master',
);
// Check total of Executed Commands
@ -207,7 +208,6 @@ class DeployCommandMiscTest extends TestCase
$this->assertNotEquals(0, $tester->getStatusCode());
}
public function testDeploymentWithSkippingTask()
{
$application = new MageApplicationMockup();

View file

@ -11,9 +11,11 @@
namespace Mage\Tests\Command\BuiltIn\Releases;
use Mage\Command\BuiltIn\Releases\ListCommand;
use Mage\Runtime\Exception\DeploymentException;
use Mage\Command\AbstractCommand;
use Mage\Tests\MageApplicationMockup;
use Symfony\Component\Console\Tester\CommandTester;
use Exception;
use PHPUnit_Framework_TestCase as TestCase;
class ListCommandTest extends TestCase
@ -45,4 +47,39 @@ class ListCommandTest extends TestCase
$this->assertEquals($command, $ranCommands[$index]);
}
}
public function testListReleasesWithInvalidEnvironment()
{
$application = new MageApplicationMockup();
$application->configure(__DIR__ . '/../../../Resources/testhost.yml');
/** @var AbstractCommand $command */
$command = $application->find('releases:list');
$this->assertTrue($command instanceof ListCommand);
$tester = new CommandTester($command);
$tester->execute(['command' => $command->getName(), 'environment' => 'developers']);
$this->assertNotEquals(0, $tester->getStatusCode());
$this->assertContains('The environment "developers" does not exists.', $tester->getDisplay());
}
public function testListReleasesWithoutReleases()
{
$application = new MageApplicationMockup();
$application->configure(__DIR__ . '/../../../Resources/testhost-without-releases.yml');
/** @var AbstractCommand $command */
$command = $application->find('releases:list');
$this->assertTrue($command instanceof ListCommand);
$tester = new CommandTester($command);
try {
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
} catch (Exception $exception) {
$this->assertTrue($exception instanceof DeploymentException);
$this->assertEquals('Releases are not enabled', $exception->getMessage());
}
}
}

View file

@ -12,8 +12,10 @@ namespace Mage\Tests\Command\BuiltIn\Releases;
use Mage\Command\BuiltIn\Releases\RollbackCommand;
use Mage\Command\AbstractCommand;
use Mage\Runtime\Exception\DeploymentException;
use Mage\Tests\MageApplicationMockup;
use Symfony\Component\Console\Tester\CommandTester;
use Exception;
use PHPUnit_Framework_TestCase as TestCase;
class RollbackCommandTest extends TestCase
@ -45,4 +47,38 @@ class RollbackCommandTest extends TestCase
$this->assertEquals($command, $ranCommands[$index]);
}
}
public function testRollbackReleaseWithInvalidEnvironment()
{
$application = new MageApplicationMockup();
$application->configure(__DIR__ . '/../../../Resources/testhost.yml');
/** @var AbstractCommand $command */
$command = $application->find('releases:rollback');
$this->assertTrue($command instanceof RollbackCommand);
$tester = new CommandTester($command);
$tester->execute(['command' => $command->getName(), 'environment' => 'developers', 'release' => '20170101015115']);
$this->assertNotEquals(0, $tester->getStatusCode());
$this->assertContains('The environment "developers" does not exists.', $tester->getDisplay());
}
public function testRollbackReleaseWithoutReleases()
{
$application = new MageApplicationMockup();
$application->configure(__DIR__ . '/../../../Resources/testhost-without-releases.yml');
/** @var AbstractCommand $command */
$command = $application->find('releases:rollback');
$this->assertTrue($command instanceof RollbackCommand);
try {
$tester = new CommandTester($command);
$tester->execute(['command' => $command->getName(), 'environment' => 'test', 'release' => '20170101015115']);
} catch (Exception $exception) {
$this->assertTrue($exception instanceof DeploymentException);
$this->assertEquals('Releases are not enabled', $exception->getMessage());
}
}
}

View file

@ -12,6 +12,7 @@ namespace Mage\Tests;
use Mage\MageApplication;
use Mage\Runtime\Exception\RuntimeException;
use Symfony\Component\Console\Tester\ApplicationTester;
use Exception;
use PHPUnit_Framework_TestCase as TestCase;
@ -35,7 +36,7 @@ class MageApplicationTest extends TestCase
}
}
public function testInValidFile()
public function testInvalidFile()
{
try {
$application = new MageApplication();
@ -45,4 +46,21 @@ class MageApplicationTest extends TestCase
$this->assertEquals(sprintf('The file "%s" does not exists or is not readable.', __DIR__ . '/Resources/this-does-not-exists.yml'), $exception->getMessage());
}
}
public function testAppDispatcher()
{
$application = new MageApplication();
$application->setAutoExit(false);
$application->configure(__DIR__ . '/Resources/basic.yml');
$this->assertTrue($application instanceof MageApplication);
$application->register('foo')->setCode(function() {
throw new \RuntimeException('foo');
});
$tester = new ApplicationTester($application);
$tester->run(['command' => 'foo']);
$this->assertContains('Oops, exception thrown while running command foo', $tester->getDisplay());
}
}

View file

@ -17,6 +17,7 @@ magephp:
- composer/install
- composer/generate-autoload
on-deploy:
- symfony/cache-clear: { env: 'dev' }
- symfony/cache-warmup: { env: 'dev' }
- symfony/assets-install: { env: 'dev' }
- symfony/assetic-dump: { env: 'dev' }