[Nostromo] Improve test coverage

This commit is contained in:
Andrés Montañez 2017-01-07 02:04:36 -03:00
parent 238777cb41
commit 6d708c35fa
11 changed files with 73 additions and 9 deletions

View file

@ -94,7 +94,6 @@ class DeployCommand extends AbstractCommand
$this->taskFactory = new TaskFactory($this->runtime);
$this->runDeployment($output);
} catch (RuntimeException $exception) {
$output->writeln('');
$output->writeln(sprintf('<error>%s</error>', $exception->getMessage()));
@ -287,12 +286,10 @@ class DeployCommand extends AbstractCommand
$this->statusCode = 180;
$this->log(sprintf('Task %s (%s) finished with FAIL', $task->getDescription(), $task->getName()));
}
} catch (SkipException $exception) {
$succeededTasks++;
$output->writeln('<fg=yellow>SKIPPED</>');
$this->log(sprintf('Task %s (%s) finished with SKIPPED, thrown SkipException', $task->getDescription(), $task->getName()));
} catch (ErrorException $exception) {
$output->writeln(sprintf('<fg=red>ERROR</> [%s]', $exception->getTrimmedMessage()));
$this->log(sprintf('Task %s (%s) finished with FAIL, with Error "%s"', $task->getDescription(), $task->getName(), $exception->getMessage()));

View file

@ -134,7 +134,6 @@ class ListCommand extends AbstractCommand
$output->writeln('');
}
}
} catch (RuntimeException $exception) {
$output->writeln(sprintf('<error>%s</error>', $exception->getMessage()));
$this->statusCode = $exception->getCode();

View file

@ -83,7 +83,6 @@ class RollbackCommand extends DeployCommand
$this->taskFactory = new TaskFactory($this->runtime);
$this->runDeployment($output);
} catch (RuntimeException $exception) {
$output->writeln(sprintf('<error>%s</error>', $exception->getMessage()));
$this->statusCode = $exception->getCode();

View file

@ -29,7 +29,6 @@ class CopyTask extends AbstractFileTask
{
try {
return sprintf('[FS] Copy "%s" to "%s"', $this->getFile('from'), $this->getFile('to'));
} catch (Exception $exception) {
return '[FS] Copy [missing parameters]';
}

View file

@ -29,7 +29,6 @@ class LinkTask extends AbstractFileTask
{
try {
return sprintf('[FS] Link "%s" to "%s"', $this->getFile('from'), $this->getFile('to'));
} catch (Exception $exception) {
return '[FS] Link [missing parameters]';
}

View file

@ -29,7 +29,6 @@ class MoveTask extends AbstractFileTask
{
try {
return sprintf('[FS] Move "%s" to "%s"', $this->getFile('from'), $this->getFile('to'));
} catch (Exception $exception) {
return '[FS] Move [missing parameters]';
}

View file

@ -29,7 +29,6 @@ class RemoveTask extends AbstractFileTask
{
try {
return sprintf('[FS] Remove "%s"', $this->getFile('file'));
} catch (Exception $exception) {
return '[FS] Remove [missing parameters]';
}

View file

@ -18,6 +18,25 @@ use PHPUnit_Framework_TestCase as TestCase;
class DeployCommandMiscTest extends TestCase
{
public function testDeploymentWithNoHosts()
{
$application = new MageApplicationMockup();
$application->configure(__DIR__ . '/../../Resources/no-hosts.yml');
/** @var AbstractCommand $command */
$command = $application->find('deploy');
$this->assertTrue($command instanceof DeployCommand);
$tester = new CommandTester($command);
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$this->assertContains('No hosts defined, skipping On Deploy tasks', $tester->getDisplay());
$this->assertContains('No hosts defined, skipping On Release tasks', $tester->getDisplay());
$this->assertContains('No hosts defined, skipping Post Release tasks', $tester->getDisplay());
$this->assertEquals(0, $tester->getStatusCode());
}
public function testDeploymentWithSudo()
{
$application = new MageApplicationMockup();

View file

@ -132,4 +132,20 @@ class DeployCommandWithReleasesTest extends TestCase
$this->assertContains('Copying files with TarGZ ... FAIL', $tester->getDisplay());
$this->assertNotEquals(0, $tester->getStatusCode());
}
public function testDeploymentWithoutReleasesForceRelease()
{
$application = new MageApplicationMockup();
$application->configure(__DIR__ . '/../../Resources/testhost-force-release.yml');
/** @var AbstractCommand $command */
$command = $application->find('deploy');
$this->assertTrue($command instanceof DeployCommand);
$tester = new CommandTester($command);
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$this->assertContains('This task is only available with releases enabled', $tester->getDisplay());
$this->assertNotEquals(0, $tester->getStatusCode());
}
}

View file

@ -0,0 +1,23 @@
magephp:
log_dir: /tmp
environments:
test:
user: tester
branch: test
host_path: /var/www/test
releases: 4
exclude:
- ./var/cache/*
- ./var/log/*
- ./web/app_dev.php
pre-deploy:
- git/update
- composer/install
- composer/dump-autoload
on-deploy:
- symfony/cache-warmup: { env: 'dev' }
- symfony/assets-install: { env: 'dev' }
- symfony/assetic-dump: { env: 'dev' }
on-release:
post-release:
post-deploy:

View file

@ -0,0 +1,15 @@
magephp:
log_dir: /tmp
environments:
test:
user: tester
branch: test
host_path: /var/www/test
exclude:
- ./var/cache/*
- ./var/log/*
- ./web/app_dev.php
hosts:
- host2
on-release:
- deploy/release