Skip to content

Commit

Permalink
[Nostromo] Improve tests and coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
andres-montanez committed Jan 5, 2017
1 parent b56e1c3 commit f4f8bfb
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 6 deletions.
10 changes: 5 additions & 5 deletions src/Mage/Tests/Command/BuiltIn/DeployCommandMiscTest.php
Expand Up @@ -39,10 +39,11 @@ public function testDeploymentWithSudo()
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
Expand Down Expand Up @@ -207,7 +208,6 @@ public function testDeploymentWithFailingPostDeployTaskCommands()
$this->assertNotEquals(0, $tester->getStatusCode());
}


public function testDeploymentWithSkippingTask()
{
$application = new MageApplicationMockup();
Expand Down
37 changes: 37 additions & 0 deletions src/Mage/Tests/Command/BuiltIn/Releases/ListCommandTest.php
Expand Up @@ -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
Expand Down Expand Up @@ -45,4 +47,39 @@ public function testListReleasesCommands()
$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());
}
}
}
36 changes: 36 additions & 0 deletions src/Mage/Tests/Command/BuiltIn/Releases/RollbackCommandTest.php
Expand Up @@ -12,8 +12,10 @@

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
Expand Down Expand Up @@ -45,4 +47,38 @@ public function testRollbackReleaseCommands()
$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());
}
}
}
20 changes: 19 additions & 1 deletion src/Mage/Tests/MageApplicationTest.php
Expand Up @@ -12,6 +12,7 @@

use Mage\MageApplication;
use Mage\Runtime\Exception\RuntimeException;
use Symfony\Component\Console\Tester\ApplicationTester;
use Exception;
use PHPUnit_Framework_TestCase as TestCase;

Expand All @@ -35,7 +36,7 @@ public function testInValidConfiguration()
}
}

public function testInValidFile()
public function testInvalidFile()
{
try {
$application = new MageApplication();
Expand All @@ -45,4 +46,21 @@ public function testInValidFile()
$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());
}
}
1 change: 1 addition & 0 deletions src/Mage/Tests/Resources/testhost-sudo.yml
Expand Up @@ -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' }
Expand Down

0 comments on commit f4f8bfb

Please sign in to comment.