[Nostromo] Improve Exception workflow

This commit is contained in:
Andrés Montañez
2017-01-07 01:53:57 -03:00
parent 6d5861ec82
commit 238777cb41
29 changed files with 216 additions and 247 deletions
@@ -13,8 +13,6 @@ namespace Mage\Tests\Command\BuiltIn;
use Mage\Command\BuiltIn\DeployCommand;
use Mage\Tests\MageApplicationMockup;
use Mage\Command\AbstractCommand;
use Mage\Runtime\Exception\RuntimeException;
use Exception;
use Symfony\Component\Console\Tester\CommandTester;
use PHPUnit_Framework_TestCase as TestCase;
@@ -95,12 +93,8 @@ class DeployCommandMiscTasksTest extends TestCase
$tester = new CommandTester($command);
try {
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$this->assertTrue(false, 'Command did not failed');
} catch (Exception $exception) {
$this->assertTrue($exception instanceof RuntimeException);
$this->assertEquals('Invalid task name "invalid/task"', $exception->getMessage());
}
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$this->assertEquals(7, $tester->getStatusCode());
$this->assertContains('Invalid task name "invalid/task"', $tester->getDisplay());
}
}
@@ -192,7 +192,6 @@ class DeployCommandMiscTest extends TestCase
3 => 'composer install --optimize-autoloader',
4 => 'composer dump-autoload --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 => 'git checkout master',
);
// Check total of Executed Commands
@@ -76,13 +76,9 @@ class ListCommandTest extends TestCase
$tester = new CommandTester($command);
try {
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$this->assertTrue(false, 'Command did not failed');
} catch (Exception $exception) {
$this->assertTrue($exception instanceof DeploymentException);
$this->assertEquals('Releases are not enabled', $exception->getMessage());
}
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$this->assertNotEquals(0, $tester->getStatusCode());
$this->assertContains('Releases are not enabled', $tester->getDisplay());
}
public function testFailToGetCurrentRelease()
@@ -96,13 +92,9 @@ class ListCommandTest extends TestCase
$tester = new CommandTester($command);
try {
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$this->assertTrue(false, 'Command did not failed');
} catch (Exception $exception) {
$this->assertTrue($exception instanceof RuntimeException);
$this->assertEquals('Unable to retrieve current release from host "host1"', $exception->getMessage());
}
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$this->assertNotEquals(0, $tester->getStatusCode());
$this->assertContains('Unable to retrieve current release from host "host1"', $tester->getDisplay());
}
public function testNoReleasesAvailable()
@@ -131,13 +123,9 @@ class ListCommandTest extends TestCase
$tester = new CommandTester($command);
try {
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$this->assertTrue(false, 'Command did not failed');
} catch (Exception $exception) {
$this->assertTrue($exception instanceof RuntimeException);
$this->assertEquals('Unable to retrieve releases from host "host3"', $exception->getMessage());
}
$tester->execute(['command' => $command->getName(), 'environment' => 'test']);
$this->assertNotEquals(0, $tester->getStatusCode());
$this->assertContains('Unable to retrieve releases from host "host3"', $tester->getDisplay());
}
public function testNoHosts()
@@ -75,13 +75,9 @@ class RollbackCommandTest extends TestCase
$tester = new CommandTester($command);
try {
$tester->execute(['command' => $command->getName(), 'environment' => 'test', 'release' => '20170101015115']);
$this->assertTrue(false, 'Command did not failed');
} catch (Exception $exception) {
$this->assertTrue($exception instanceof DeploymentException);
$this->assertEquals('Releases are not enabled', $exception->getMessage());
}
$tester->execute(['command' => $command->getName(), 'environment' => 'test', 'release' => '20170101015115']);
$this->assertNotEquals(0, $tester->getStatusCode());
$this->assertContains('Releases are not enabled', $tester->getDisplay());
}
public function testRollbackReleaseNotAvailable()
@@ -95,12 +91,8 @@ class RollbackCommandTest extends TestCase
$tester = new CommandTester($command);
try {
$tester->execute(['command' => $command->getName(), 'environment' => 'test', 'release' => '20170101015115']);
$this->assertTrue(false, 'Command did not failed');
} catch (Exception $exception) {
$this->assertTrue($exception instanceof DeploymentException);
$this->assertEquals('Release "20170101015115" is not available on all hosts', $exception->getMessage());
}
$tester->execute(['command' => $command->getName(), 'environment' => 'test', 'release' => '20170101015115']);
$this->assertNotEquals(0, $tester->getStatusCode());
$this->assertContains('Release "20170101015115" is not available on all hosts', $tester->getDisplay());
}
}
+3 -3
View File
@@ -10,8 +10,8 @@
namespace Mage\Tests\Runtime;
use Mage\Runtime\Exception\RuntimeException;
use Mage\Runtime\Runtime;
use Mage\Runtime\Exception\InvalidEnvironmentException;
use Exception;
use Monolog\Logger;
use Monolog\Handler\TestHandler;
@@ -66,7 +66,7 @@ class RuntimeTest extends TestCase
$runtime = new Runtime();
$runtime->setEnvironment('invalid');
} catch (Exception $exception) {
$this->assertTrue($exception instanceof InvalidEnvironmentException);
$this->assertTrue($exception instanceof RuntimeException);
}
try {
@@ -74,7 +74,7 @@ class RuntimeTest extends TestCase
$runtime->setConfiguration(['environments' => ['valid' => []]]);
$runtime->setEnvironment('invalid');
} catch (Exception $exception) {
$this->assertTrue($exception instanceof InvalidEnvironmentException);
$this->assertTrue($exception instanceof RuntimeException);
}
}
+1 -1
View File
@@ -10,7 +10,7 @@
namespace Mage\Tests\Task;
use Mage\Task\ErrorException;
use Mage\Task\Exception\ErrorException;
use Exception;
use PHPUnit_Framework_TestCase as TestCase;
@@ -10,7 +10,7 @@
namespace Mage\Tests\Task\BuiltIn;
use Mage\Runtime\Exception\RuntimeException;
use Mage\Task\Exception\ErrorException;
use Mage\Task\BuiltIn\FS\CopyTask;
use Mage\Task\BuiltIn\FS\LinkTask;
use Mage\Task\BuiltIn\FS\MoveTask;
@@ -121,10 +121,11 @@ class FileSystemTaskTest extends TestCase
$task->setRuntime($runtime);
try {
$this->assertContains('[missing parameters]', $task->getDescription());
$task->execute();
$this->assertTrue(false, 'Task did not failed');
} catch (Exception $exception) {
$this->assertTrue($exception instanceof RuntimeException);
$this->assertTrue($exception instanceof ErrorException);
$this->assertEquals('Parameter "from" is not defined', $exception->getMessage());
}
}
@@ -198,10 +199,11 @@ class FileSystemTaskTest extends TestCase
$task->setRuntime($runtime);
try {
$this->assertContains('[missing parameters]', $task->getDescription());
$task->execute();
$this->assertTrue(false, 'Task did not failed');
} catch (Exception $exception) {
$this->assertTrue($exception instanceof RuntimeException);
$this->assertTrue($exception instanceof ErrorException);
$this->assertEquals('Parameter "from" is not defined', $exception->getMessage());
}
}
@@ -273,10 +275,11 @@ class FileSystemTaskTest extends TestCase
$task->setRuntime($runtime);
try {
$this->assertContains('[missing parameters]', $task->getDescription());
$task->execute();
$this->assertTrue(false, 'Task did not failed');
} catch (Exception $exception) {
$this->assertTrue($exception instanceof RuntimeException);
$this->assertTrue($exception instanceof ErrorException);
$this->assertEquals('Parameter "file" is not defined', $exception->getMessage());
}
}
@@ -350,10 +353,11 @@ class FileSystemTaskTest extends TestCase
$task->setRuntime($runtime);
try {
$this->assertContains('[missing parameters]', $task->getDescription());
$task->execute();
$this->assertTrue(false, 'Task did not failed');
} catch (Exception $exception) {
$this->assertTrue($exception instanceof RuntimeException);
$this->assertTrue($exception instanceof ErrorException);
$this->assertEquals('Parameter "from" is not defined', $exception->getMessage());
}
}
+1 -1
View File
@@ -10,7 +10,7 @@
namespace Mage\Tests\Task;
use Mage\Task\ErrorException;
use Mage\Task\Exception\ErrorException;
use Mage\Task\AbstractTask;
class TestCaseFailTask extends AbstractTask
+3 -3
View File
@@ -19,9 +19,9 @@ class UtilsTest extends TestCase
{
public function testStageNames()
{
$this->assertEquals('Pre Deployment', Utils::getStageName(Runtime::PRE_DEPLOY));
$this->assertEquals('On Deployment', Utils::getStageName(Runtime::ON_DEPLOY));
$this->assertEquals('Post Deployment', Utils::getStageName(Runtime::POST_DEPLOY));
$this->assertEquals('Pre Deploy', Utils::getStageName(Runtime::PRE_DEPLOY));
$this->assertEquals('On Deploy', Utils::getStageName(Runtime::ON_DEPLOY));
$this->assertEquals('Post Deploy', Utils::getStageName(Runtime::POST_DEPLOY));
$this->assertEquals('On Release', Utils::getStageName(Runtime::ON_RELEASE));
$this->assertEquals('Post Release', Utils::getStageName(Runtime::POST_RELEASE));
$this->assertEquals('invalid-stage', Utils::getStageName('invalid-stage'));