From 3c21cfcce96fbc9e84a1028a3f698423221e30ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Monta=C3=B1ez?= Date: Sun, 1 Jan 2017 18:20:43 -0300 Subject: [PATCH] [Nostromo] Add more and tweak Tests --- src/Mage/Runtime/Runtime.php | 6 +- src/Mage/Task/ErrorException.php | 2 +- .../BuiltIn/Config/DumpCommandTest.php | 11 +- .../Config/EnvironmentsCommandTest.php | 11 +- .../Command/BuiltIn/DeployCommandTest.php | 61 ++++---- .../BuiltIn/Releases/ListCommandTest.php | 13 +- .../BuiltIn/Releases/RollbackCommandTest.php | 13 +- .../Command/BuiltIn/VersionCommandTest.php | 9 ++ src/Mage/Tests/MageTestApplication.php | 15 -- src/Mage/Tests/Runtime/ProcessMockup.php | 9 ++ src/Mage/Tests/Runtime/RuntimeMockup.php | 9 ++ src/Mage/Tests/Runtime/RuntimeTest.php | 145 ++++++++++++++++++ src/Mage/Tests/Task/AbstractTaskTest.php | 44 ++++++ src/Mage/Tests/Task/TestCaseFailTask.php | 32 ++++ src/Mage/Tests/Task/TestCaseTask.php | 36 +++++ src/Mage/Tests/UtilsTest.php | 41 +++-- 16 files changed, 389 insertions(+), 68 deletions(-) create mode 100644 src/Mage/Tests/Runtime/RuntimeTest.php create mode 100644 src/Mage/Tests/Task/AbstractTaskTest.php create mode 100644 src/Mage/Tests/Task/TestCaseFailTask.php create mode 100644 src/Mage/Tests/Task/TestCaseTask.php diff --git a/src/Mage/Runtime/Runtime.php b/src/Mage/Runtime/Runtime.php index 5fb8ba1..297a074 100644 --- a/src/Mage/Runtime/Runtime.php +++ b/src/Mage/Runtime/Runtime.php @@ -31,7 +31,7 @@ class Runtime /** * @var array Magallanes configuration */ - protected $configuration; + protected $configuration = []; /** * @var string|null Environment being deployed @@ -214,6 +214,10 @@ class Runtime */ public function getEnvironmentConfig($key = null, $default = null) { + if (!array_key_exists('environments', $this->configuration) || !is_array($this->configuration['environments'])) { + return []; + } + if (!array_key_exists($this->environment, $this->configuration['environments'])) { return []; } diff --git a/src/Mage/Task/ErrorException.php b/src/Mage/Task/ErrorException.php index 6fb64a4..ffd565f 100644 --- a/src/Mage/Task/ErrorException.php +++ b/src/Mage/Task/ErrorException.php @@ -19,7 +19,7 @@ use Exception; */ class ErrorException extends Exception { - public function getTrimmedMessage($maxLength = 80) + public function getTrimmedMessage($maxLength = 60) { $message = $this->getMessage(); diff --git a/src/Mage/Tests/Command/BuiltIn/Config/DumpCommandTest.php b/src/Mage/Tests/Command/BuiltIn/Config/DumpCommandTest.php index bb526a4..6440ad0 100644 --- a/src/Mage/Tests/Command/BuiltIn/Config/DumpCommandTest.php +++ b/src/Mage/Tests/Command/BuiltIn/Config/DumpCommandTest.php @@ -1,4 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Mage\Tests\Command\BuiltIn\Config; use Mage\Command\BuiltIn\Config\DumpCommand; @@ -22,6 +31,6 @@ class DumpCommandTest extends TestCase $tester = new CommandTester($command); $tester->execute(['command' => $command->getName()]); - $this->assertEquals($tester->getStatusCode(), 0); + $this->assertEquals(0, $tester->getStatusCode()); } } diff --git a/src/Mage/Tests/Command/BuiltIn/Config/EnvironmentsCommandTest.php b/src/Mage/Tests/Command/BuiltIn/Config/EnvironmentsCommandTest.php index bf1c689..9bbf63f 100644 --- a/src/Mage/Tests/Command/BuiltIn/Config/EnvironmentsCommandTest.php +++ b/src/Mage/Tests/Command/BuiltIn/Config/EnvironmentsCommandTest.php @@ -1,4 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Mage\Tests\Command\BuiltIn\Config; use Mage\Command\BuiltIn\Config\EnvironmentsCommand; @@ -88,6 +97,6 @@ class EnvironmentsCommandTest extends TestCase $tester = new CommandTester($command); $tester->execute(['command' => $command->getName()]); - $this->assertEquals($tester->getStatusCode(), 0); + $this->assertEquals(0, $tester->getStatusCode()); } } diff --git a/src/Mage/Tests/Command/BuiltIn/DeployCommandTest.php b/src/Mage/Tests/Command/BuiltIn/DeployCommandTest.php index 65075ef..23ab263 100644 --- a/src/Mage/Tests/Command/BuiltIn/DeployCommandTest.php +++ b/src/Mage/Tests/Command/BuiltIn/DeployCommandTest.php @@ -1,4 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Mage\Tests\Command\BuiltIn; use Mage\Command\BuiltIn\DeployCommand; @@ -118,14 +127,14 @@ class DeployCommandTest extends TestCase ); // Check total of Executed Commands - $this->assertEquals(count($ranCommands), count($testCase)); + $this->assertEquals(count($testCase), count($ranCommands)); // Check Generated Commands foreach ($testCase as $index => $command) { - $this->assertEquals($ranCommands[$index], $command); + $this->assertEquals($command, $ranCommands[$index]); } - $this->assertEquals($tester->getStatusCode(), 0); + $this->assertEquals(0, $tester->getStatusCode()); } public function testDeploymentWithErrorTaskCommands() @@ -197,16 +206,16 @@ class DeployCommandTest extends TestCase ); // Check total of Executed Commands - $this->assertEquals(count($ranCommands), count($testCase)); + $this->assertEquals(count($testCase), count($ranCommands)); // Check Generated Commands foreach ($testCase as $index => $command) { - $this->assertEquals($ranCommands[$index], $command); + $this->assertEquals($command, $ranCommands[$index]); } $this->assertTrue(strpos($tester->getDisplay(), 'ERROR') !== false); - $this->assertNotEquals($tester->getStatusCode(), 0); + $this->assertNotEquals(0, $tester->getStatusCode()); } public function testDeploymentWithFailingPostDeployTaskCommands() @@ -255,8 +264,6 @@ class DeployCommandTest extends TestCase ) ); - $runtime->setReleaseId('20170101015120'); - /** @var AbstractCommand $command */ $command = $application->find('deploy'); $command->setRuntime($runtime); @@ -277,16 +284,16 @@ class DeployCommandTest extends TestCase ); // Check total of Executed Commands - $this->assertEquals(count($ranCommands), count($testCase)); + $this->assertEquals(count($testCase), count($ranCommands)); // Check Generated Commands foreach ($testCase as $index => $command) { - $this->assertEquals($ranCommands[$index], $command); + $this->assertEquals($command, $ranCommands[$index]); } $this->assertTrue(strpos($tester->getDisplay(), 'ERROR') !== false); - $this->assertNotEquals($tester->getStatusCode(), 0); + $this->assertNotEquals(0, $tester->getStatusCode()); } public function testDeploymentWithoutReleasesCommands() @@ -359,8 +366,6 @@ class DeployCommandTest extends TestCase ) ); - $runtime->setReleaseId('1234567890'); - /** @var AbstractCommand $command */ $command = $application->find('deploy'); $command->setRuntime($runtime); @@ -377,22 +382,22 @@ class DeployCommandTest extends TestCase 3 => 'composer install --dev', 4 => 'composer dumpautoload --optimize', 5 => 'rsync -avz --exclude=.git --exclude=vendor --exclude=app/cache --exclude=app/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/releases/1234567890 \\&\\& 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/releases/1234567890 \\&\\& 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/releases/1234567890 \\&\\& 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/releases/1234567890 \\&\\& bin/console assetic:dump --env=dev \\"', + 6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& 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 \\&\\& 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 \\&\\& 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 \\&\\& bin/console assetic:dump --env=dev \\"', 10 => 'git checkout master', ); // Check total of Executed Commands - $this->assertEquals(count($ranCommands), count($testCase)); + $this->assertEquals(count($testCase), count($ranCommands)); // Check Generated Commands foreach ($testCase as $index => $command) { - $this->assertEquals($ranCommands[$index], $command); + $this->assertEquals($command, $ranCommands[$index]); } - $this->assertEquals($tester->getStatusCode(), 0); + $this->assertEquals(0, $tester->getStatusCode()); } public function testDeploymentWithSkippingTask() @@ -465,8 +470,6 @@ class DeployCommandTest extends TestCase ) ); - $runtime->setReleaseId('1234567890'); - /** @var AbstractCommand $command */ $command = $application->find('deploy'); $command->setRuntime($runtime); @@ -482,23 +485,23 @@ class DeployCommandTest extends TestCase 2 => 'composer install --dev', 3 => 'composer dumpautoload --optimize', 4 => 'rsync -avz --exclude=.git --exclude=vendor --exclude=app/cache --exclude=app/log --exclude=web/app_dev.php ./ tester@testhost:/var/www/test', - 5 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test/releases/1234567890 \\&\\& bin/console cache:clear --env=dev \\"', - 6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test/releases/1234567890 \\&\\& 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/releases/1234567890 \\&\\& 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/releases/1234567890 \\&\\& bin/console assetic:dump --env=dev \\"', + 5 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& bin/console cache:clear --env=dev \\"', + 6 => 'ssh -p 22 -q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no tester@testhost sh -c \\"cd /var/www/test \\&\\& 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 \\&\\& 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 \\&\\& bin/console assetic:dump --env=dev \\"', 9 => 'git branch | grep "*"', ); // Check total of Executed Commands - $this->assertEquals(count($ranCommands), count($testCase)); + $this->assertEquals(count($testCase), count($ranCommands)); // Check Generated Commands foreach ($testCase as $index => $command) { - $this->assertEquals($ranCommands[$index], $command); + $this->assertEquals($command, $ranCommands[$index]); } $this->assertTrue(strpos($tester->getDisplay(), 'SKIPPED') !== false); - $this->assertEquals($tester->getStatusCode(), 0); + $this->assertEquals(0, $tester->getStatusCode()); } } diff --git a/src/Mage/Tests/Command/BuiltIn/Releases/ListCommandTest.php b/src/Mage/Tests/Command/BuiltIn/Releases/ListCommandTest.php index 38dc17d..7c2465c 100644 --- a/src/Mage/Tests/Command/BuiltIn/Releases/ListCommandTest.php +++ b/src/Mage/Tests/Command/BuiltIn/Releases/ListCommandTest.php @@ -1,4 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Mage\Tests\Command\BuiltIn\Releases; use Mage\Command\BuiltIn\Releases\ListCommand; @@ -96,11 +105,11 @@ class ListCommandTest extends TestCase ); // Check total of Executed Commands - $this->assertEquals(count($ranCommands), count($testCase)); + $this->assertEquals(count($testCase), count($ranCommands)); // Check Generated Commands foreach ($testCase as $index => $command) { - $this->assertEquals($ranCommands[$index], $command); + $this->assertEquals($command, $ranCommands[$index]); } } } diff --git a/src/Mage/Tests/Command/BuiltIn/Releases/RollbackCommandTest.php b/src/Mage/Tests/Command/BuiltIn/Releases/RollbackCommandTest.php index 31f7226..223716c 100644 --- a/src/Mage/Tests/Command/BuiltIn/Releases/RollbackCommandTest.php +++ b/src/Mage/Tests/Command/BuiltIn/Releases/RollbackCommandTest.php @@ -1,4 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Mage\Tests\Command\BuiltIn\Releases; use Mage\Command\BuiltIn\Releases\RollbackCommand; @@ -96,11 +105,11 @@ class RollbackCommandTest extends TestCase ); // Check total of Executed Commands - $this->assertEquals(count($ranCommands), count($testCase)); + $this->assertEquals(count($testCase), count($ranCommands)); // Check Generated Commands foreach ($testCase as $index => $command) { - $this->assertEquals($ranCommands[$index], $command); + $this->assertEquals($command, $ranCommands[$index]); } } } diff --git a/src/Mage/Tests/Command/BuiltIn/VersionCommandTest.php b/src/Mage/Tests/Command/BuiltIn/VersionCommandTest.php index 7b50312..80ec95b 100644 --- a/src/Mage/Tests/Command/BuiltIn/VersionCommandTest.php +++ b/src/Mage/Tests/Command/BuiltIn/VersionCommandTest.php @@ -1,4 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Mage\Tests\Command\BuiltIn; use Mage\Command\BuiltIn\VersionCommand; diff --git a/src/Mage/Tests/MageTestApplication.php b/src/Mage/Tests/MageTestApplication.php index 0aa5859..a1d55e1 100644 --- a/src/Mage/Tests/MageTestApplication.php +++ b/src/Mage/Tests/MageTestApplication.php @@ -10,23 +10,8 @@ namespace Mage\Tests; -use Mage\Command\AbstractCommand; -use Mage\Runtime\Runtime; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Finder\Finder; -use Symfony\Component\Finder\SplFileInfo; -use Monolog\Logger; -use Monolog\Handler\StreamHandler; use Symfony\Component\Console\Application; -use Symfony\Component\Yaml\Yaml; -use Mage\Runtime\Exception\RuntimeException; -/** - * The Console Application for launching the Mage command in a standalone instance - * - * @author Andrés Montañez - */ class MageTestApplication extends Application { } diff --git a/src/Mage/Tests/Runtime/ProcessMockup.php b/src/Mage/Tests/Runtime/ProcessMockup.php index dc2f04d..5e10a0c 100644 --- a/src/Mage/Tests/Runtime/ProcessMockup.php +++ b/src/Mage/Tests/Runtime/ProcessMockup.php @@ -1,4 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Mage\Tests\Runtime; use Symfony\Component\Process\Process; diff --git a/src/Mage/Tests/Runtime/RuntimeMockup.php b/src/Mage/Tests/Runtime/RuntimeMockup.php index 4420cea..496c7ea 100644 --- a/src/Mage/Tests/Runtime/RuntimeMockup.php +++ b/src/Mage/Tests/Runtime/RuntimeMockup.php @@ -1,4 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Mage\Tests\Runtime; use Mage\Runtime\Runtime; diff --git a/src/Mage/Tests/Runtime/RuntimeTest.php b/src/Mage/Tests/Runtime/RuntimeTest.php new file mode 100644 index 0000000..d468d21 --- /dev/null +++ b/src/Mage/Tests/Runtime/RuntimeTest.php @@ -0,0 +1,145 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Mage\Tests\Runtime; + +use Mage\Runtime\Runtime; +use Mage\Runtime\Exception\InvalidEnvironmentException; +use Exception; +use Monolog\Logger; +use Monolog\Handler\TestHandler; +use PHPUnit_Framework_TestCase as TestCase; +use Psr\Log\LogLevel; +use Symfony\Component\Process\Process; + +class RuntimeTest extends TestCase +{ + public function testReleaseIdGeneration() + { + $releaseId = date('YmdHis'); + + $runtime = new Runtime(); + $runtime->generateReleaseId(); + + $this->assertEquals($releaseId, $runtime->getReleaseId()); + } + + public function testEmptyEnvironmentConfig() + { + $runtime = new Runtime(); + $config = $runtime->getEnvironmentConfig(); + + $this->assertTrue(is_array($config)); + $this->assertEquals(0, count($config)); + } + + public function testInvalidEnvironments() + { + try { + $runtime = new Runtime(); + $runtime->setEnvironment('invalid'); + } catch (Exception $exception) { + $this->assertTrue($exception instanceof InvalidEnvironmentException); + } + + try { + $runtime = new Runtime(); + $runtime->setConfiguration(['environments' => ['valid' => []]]); + $runtime->setEnvironment('invalid'); + } catch (Exception $exception) { + $this->assertTrue($exception instanceof InvalidEnvironmentException); + } + } + + public function testTempFile() + { + $runtime = new Runtime(); + $tempFile = $runtime->getTempFile(); + + $this->assertNotEquals('', $tempFile); + $this->assertTrue(file_exists($tempFile)); + $this->assertEquals(0, filesize($tempFile)); + } + + public function testSSHConfigUndefinedOptions() + { + $runtime = new Runtime(); + $sshConfig = $runtime->getSSHConfig(); + + $this->assertTrue(is_array($sshConfig)); + + $this->assertTrue(array_key_exists('port', $sshConfig)); + $this->assertEquals('22', $sshConfig['port']); + + $this->assertTrue(array_key_exists('flags', $sshConfig)); + $this->assertEquals('-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no', $sshConfig['flags']); + } + + public function testSSHConfigEmptyOptions() + { + $runtime = new Runtime(); + $runtime->setConfiguration(['environments' => ['test' => ['ssh' => []]]]); + $runtime->setEnvironment('test'); + $sshConfig = $runtime->getSSHConfig(); + + $this->assertTrue(is_array($sshConfig)); + + $this->assertTrue(array_key_exists('port', $sshConfig)); + $this->assertEquals('22', $sshConfig['port']); + + $this->assertTrue(array_key_exists('flags', $sshConfig)); + $this->assertEquals('-q -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no', $sshConfig['flags']); + } + + public function testSSHConfigCustomOptions() + { + $runtime = new Runtime(); + $runtime->setConfiguration(['environments' => ['test' => ['ssh' => ['port' => '2222', 'flags' => '-q']]]]); + $runtime->setEnvironment('test'); + $sshConfig = $runtime->getSSHConfig(); + + $this->assertTrue(is_array($sshConfig)); + + $this->assertTrue(array_key_exists('port', $sshConfig)); + $this->assertEquals('2222', $sshConfig['port']); + + $this->assertTrue(array_key_exists('flags', $sshConfig)); + $this->assertEquals('-q', $sshConfig['flags']); + } + + public function testLogger() + { + $logger = new Logger('test'); + $handler = new TestHandler(); + $logger->pushHandler($handler); + + $runtime = new Runtime(); + $runtime->setLogger($logger); + + $runtime->log('Test Message', LogLevel::INFO); + + $this->assertTrue($handler->hasInfoRecords()); + $this->assertTrue($handler->hasInfo('Test Message')); + } + + public function testLocalCommand() + { + $runtime = new Runtime(); + + /** @var Process $process */ + $process = $runtime->runLocalCommand('date +%s'); + $this->assertTrue($process->isSuccessful()); + $this->assertEquals(time(), trim($process->getOutput())); + + /** @var Process $process */ + $process = $runtime->runLocalCommand('false'); + $this->assertFalse($process->isSuccessful()); + } +} diff --git a/src/Mage/Tests/Task/AbstractTaskTest.php b/src/Mage/Tests/Task/AbstractTaskTest.php new file mode 100644 index 0000000..215c760 --- /dev/null +++ b/src/Mage/Tests/Task/AbstractTaskTest.php @@ -0,0 +1,44 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Mage\Tests\Task; + +use Mage\Task\ErrorException; +use Exception; +use PHPUnit_Framework_TestCase as TestCase; + +class AbstractTaskTest extends TestCase +{ + public function testNotArrayOptions() + { + $task = new TestCaseTask(); + $task->setOptions('not an array'); + + $this->assertTrue(is_array($task->getOptions())); + } + + public function testFailingTask() + { + $task = new TestCaseFailTask(); + + try { + $task->execute(); + $this->assertTrue(false, 'TestCaseFailTask did not throw exception'); + } catch (Exception $exception) { + $this->assertTrue($exception instanceof ErrorException); + + if ($exception instanceof ErrorException) { + $this->assertEquals('This is a text...', $exception->getTrimmedMessage(14)); + $this->assertEquals('This is a text with a lot of characters', $exception->getTrimmedMessage()); + $this->assertEquals('This is a text with a lot of characters', $exception->getMessage()); + } + } + } +} diff --git a/src/Mage/Tests/Task/TestCaseFailTask.php b/src/Mage/Tests/Task/TestCaseFailTask.php new file mode 100644 index 0000000..b206e3a --- /dev/null +++ b/src/Mage/Tests/Task/TestCaseFailTask.php @@ -0,0 +1,32 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Mage\Tests\Task; + +use Mage\Task\ErrorException; +use Mage\Task\AbstractTask; + +class TestCaseFailTask extends AbstractTask +{ + public function getName() + { + return 'test-fail'; + } + + public function getDescription() + { + return '[Test] This is a Test Task which Fails'; + } + + public function execute() + { + throw new ErrorException('This is a text with a lot of characters'); + } +} diff --git a/src/Mage/Tests/Task/TestCaseTask.php b/src/Mage/Tests/Task/TestCaseTask.php new file mode 100644 index 0000000..daa1656 --- /dev/null +++ b/src/Mage/Tests/Task/TestCaseTask.php @@ -0,0 +1,36 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace Mage\Tests\Task; + +use Mage\Task\AbstractTask; + +class TestCaseTask extends AbstractTask +{ + public function getName() + { + return 'test'; + } + + public function getDescription() + { + return '[Test] This is a Test Task'; + } + + public function execute() + { + return true; + } + + public function getOptions() + { + return $this->options; + } +} diff --git a/src/Mage/Tests/UtilsTest.php b/src/Mage/Tests/UtilsTest.php index 85372dd..ddeb2ba 100644 --- a/src/Mage/Tests/UtilsTest.php +++ b/src/Mage/Tests/UtilsTest.php @@ -1,4 +1,13 @@ + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + namespace Mage\Tests; use Mage\Utils; @@ -10,11 +19,11 @@ class UtilsTest extends TestCase { public function testStageNames() { - $this->assertEquals(Utils::getStageName(Runtime::PRE_DEPLOY), 'Pre Deployment'); - $this->assertEquals(Utils::getStageName(Runtime::ON_DEPLOY), 'On Deployment'); - $this->assertEquals(Utils::getStageName(Runtime::POST_DEPLOY), 'Post Deployment'); - $this->assertEquals(Utils::getStageName(Runtime::ON_RELEASE), 'On Release'); - $this->assertEquals(Utils::getStageName(Runtime::POST_RELEASE), 'Post Release'); + $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('On Release', Utils::getStageName(Runtime::ON_RELEASE)); + $this->assertEquals('Post Release', Utils::getStageName(Runtime::POST_RELEASE)); } public function testReleaseDate() @@ -24,49 +33,49 @@ class UtilsTest extends TestCase $this->assertTrue($dateTime instanceof DateTime); - $this->assertEquals($dateTime->format('Y-m-d H:i:s'), '2017-01-02 03:15:30'); + $this->assertEquals('2017-01-02 03:15:30', $dateTime->format('Y-m-d H:i:s')); } public function testTimeDiffs() { $dateTime = new DateTime(); $dateTime->modify('-1 second'); - $this->assertEquals(Utils::getTimeDiff($dateTime), 'just now'); + $this->assertEquals('just now', Utils::getTimeDiff($dateTime)); $dateTime = new DateTime(); $dateTime->modify('-45 seconds'); - $this->assertEquals(Utils::getTimeDiff($dateTime), '45 seconds ago'); + $this->assertEquals('45 seconds ago', Utils::getTimeDiff($dateTime)); $dateTime = new DateTime(); $dateTime->modify('-90 seconds'); - $this->assertEquals(Utils::getTimeDiff($dateTime), 'one minute ago'); + $this->assertEquals('one minute ago', Utils::getTimeDiff($dateTime)); $dateTime = new DateTime(); $dateTime->modify('-30 minutes'); - $this->assertEquals(Utils::getTimeDiff($dateTime), '30 minutes ago'); + $this->assertEquals('30 minutes ago', Utils::getTimeDiff($dateTime)); $dateTime = new DateTime(); $dateTime->modify('-1 hour'); - $this->assertEquals(Utils::getTimeDiff($dateTime), 'one hour ago'); + $this->assertEquals('one hour ago', Utils::getTimeDiff($dateTime)); $dateTime = new DateTime(); $dateTime->modify('-10 hours'); - $this->assertEquals(Utils::getTimeDiff($dateTime), '10 hours ago'); + $this->assertEquals('10 hours ago', Utils::getTimeDiff($dateTime)); $dateTime = new DateTime(); $dateTime->modify('-1 day'); - $this->assertEquals(Utils::getTimeDiff($dateTime), 'one day ago'); + $this->assertEquals('one day ago', Utils::getTimeDiff($dateTime)); $dateTime = new DateTime(); $dateTime->modify('-3 days'); - $this->assertEquals(Utils::getTimeDiff($dateTime), '3 days ago'); + $this->assertEquals('3 days ago', Utils::getTimeDiff($dateTime)); $dateTime = new DateTime(); $dateTime->modify('-7 days'); - $this->assertEquals(Utils::getTimeDiff($dateTime), 'a week ago'); + $this->assertEquals('a week ago', Utils::getTimeDiff($dateTime)); $dateTime = new DateTime(); $dateTime->modify('-10 days'); - $this->assertEquals(Utils::getTimeDiff($dateTime), ''); + $this->assertEquals('', Utils::getTimeDiff($dateTime)); } }