Browse Source

[Nostromo] Add more and tweak Tests

pull/1/head
Andrés Montañez 8 years ago
parent
commit
3c21cfcce9
  1. 6
      src/Mage/Runtime/Runtime.php
  2. 2
      src/Mage/Task/ErrorException.php
  3. 11
      src/Mage/Tests/Command/BuiltIn/Config/DumpCommandTest.php
  4. 11
      src/Mage/Tests/Command/BuiltIn/Config/EnvironmentsCommandTest.php
  5. 61
      src/Mage/Tests/Command/BuiltIn/DeployCommandTest.php
  6. 13
      src/Mage/Tests/Command/BuiltIn/Releases/ListCommandTest.php
  7. 13
      src/Mage/Tests/Command/BuiltIn/Releases/RollbackCommandTest.php
  8. 9
      src/Mage/Tests/Command/BuiltIn/VersionCommandTest.php
  9. 15
      src/Mage/Tests/MageTestApplication.php
  10. 9
      src/Mage/Tests/Runtime/ProcessMockup.php
  11. 9
      src/Mage/Tests/Runtime/RuntimeMockup.php
  12. 145
      src/Mage/Tests/Runtime/RuntimeTest.php
  13. 44
      src/Mage/Tests/Task/AbstractTaskTest.php
  14. 32
      src/Mage/Tests/Task/TestCaseFailTask.php
  15. 36
      src/Mage/Tests/Task/TestCaseTask.php
  16. 41
      src/Mage/Tests/UtilsTest.php

6
src/Mage/Runtime/Runtime.php

@ -31,7 +31,7 @@ class Runtime
/** /**
* @var array Magallanes configuration * @var array Magallanes configuration
*/ */
protected $configuration; protected $configuration = [];
/** /**
* @var string|null Environment being deployed * @var string|null Environment being deployed
@ -214,6 +214,10 @@ class Runtime
*/ */
public function getEnvironmentConfig($key = null, $default = null) 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'])) { if (!array_key_exists($this->environment, $this->configuration['environments'])) {
return []; return [];
} }

2
src/Mage/Task/ErrorException.php

@ -19,7 +19,7 @@ use Exception;
*/ */
class ErrorException extends Exception class ErrorException extends Exception
{ {
public function getTrimmedMessage($maxLength = 80) public function getTrimmedMessage($maxLength = 60)
{ {
$message = $this->getMessage(); $message = $this->getMessage();

11
src/Mage/Tests/Command/BuiltIn/Config/DumpCommandTest.php

@ -1,4 +1,13 @@
<?php <?php
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* 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; namespace Mage\Tests\Command\BuiltIn\Config;
use Mage\Command\BuiltIn\Config\DumpCommand; use Mage\Command\BuiltIn\Config\DumpCommand;
@ -22,6 +31,6 @@ class DumpCommandTest extends TestCase
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute(['command' => $command->getName()]); $tester->execute(['command' => $command->getName()]);
$this->assertEquals($tester->getStatusCode(), 0); $this->assertEquals(0, $tester->getStatusCode());
} }
} }

11
src/Mage/Tests/Command/BuiltIn/Config/EnvironmentsCommandTest.php

@ -1,4 +1,13 @@
<?php <?php
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* 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; namespace Mage\Tests\Command\BuiltIn\Config;
use Mage\Command\BuiltIn\Config\EnvironmentsCommand; use Mage\Command\BuiltIn\Config\EnvironmentsCommand;
@ -88,6 +97,6 @@ class EnvironmentsCommandTest extends TestCase
$tester = new CommandTester($command); $tester = new CommandTester($command);
$tester->execute(['command' => $command->getName()]); $tester->execute(['command' => $command->getName()]);
$this->assertEquals($tester->getStatusCode(), 0); $this->assertEquals(0, $tester->getStatusCode());
} }
} }

61
src/Mage/Tests/Command/BuiltIn/DeployCommandTest.php

@ -1,4 +1,13 @@
<?php <?php
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mage\Tests\Command\BuiltIn; namespace Mage\Tests\Command\BuiltIn;
use Mage\Command\BuiltIn\DeployCommand; use Mage\Command\BuiltIn\DeployCommand;
@ -118,14 +127,14 @@ class DeployCommandTest extends TestCase
); );
// Check total of Executed Commands // Check total of Executed Commands
$this->assertEquals(count($ranCommands), count($testCase)); $this->assertEquals(count($testCase), count($ranCommands));
// Check Generated Commands // Check Generated Commands
foreach ($testCase as $index => $command) { 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() public function testDeploymentWithErrorTaskCommands()
@ -197,16 +206,16 @@ class DeployCommandTest extends TestCase
); );
// Check total of Executed Commands // Check total of Executed Commands
$this->assertEquals(count($ranCommands), count($testCase)); $this->assertEquals(count($testCase), count($ranCommands));
// Check Generated Commands // Check Generated Commands
foreach ($testCase as $index => $command) { foreach ($testCase as $index => $command) {
$this->assertEquals($ranCommands[$index], $command); $this->assertEquals($command, $ranCommands[$index]);
} }
$this->assertTrue(strpos($tester->getDisplay(), 'ERROR') !== false); $this->assertTrue(strpos($tester->getDisplay(), 'ERROR') !== false);
$this->assertNotEquals($tester->getStatusCode(), 0); $this->assertNotEquals(0, $tester->getStatusCode());
} }
public function testDeploymentWithFailingPostDeployTaskCommands() public function testDeploymentWithFailingPostDeployTaskCommands()
@ -255,8 +264,6 @@ class DeployCommandTest extends TestCase
) )
); );
$runtime->setReleaseId('20170101015120');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('deploy'); $command = $application->find('deploy');
$command->setRuntime($runtime); $command->setRuntime($runtime);
@ -277,16 +284,16 @@ class DeployCommandTest extends TestCase
); );
// Check total of Executed Commands // Check total of Executed Commands
$this->assertEquals(count($ranCommands), count($testCase)); $this->assertEquals(count($testCase), count($ranCommands));
// Check Generated Commands // Check Generated Commands
foreach ($testCase as $index => $command) { foreach ($testCase as $index => $command) {
$this->assertEquals($ranCommands[$index], $command); $this->assertEquals($command, $ranCommands[$index]);
} }
$this->assertTrue(strpos($tester->getDisplay(), 'ERROR') !== false); $this->assertTrue(strpos($tester->getDisplay(), 'ERROR') !== false);
$this->assertNotEquals($tester->getStatusCode(), 0); $this->assertNotEquals(0, $tester->getStatusCode());
} }
public function testDeploymentWithoutReleasesCommands() public function testDeploymentWithoutReleasesCommands()
@ -359,8 +366,6 @@ class DeployCommandTest extends TestCase
) )
); );
$runtime->setReleaseId('1234567890');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('deploy'); $command = $application->find('deploy');
$command->setRuntime($runtime); $command->setRuntime($runtime);
@ -377,22 +382,22 @@ class DeployCommandTest extends TestCase
3 => 'composer install --dev', 3 => 'composer install --dev',
4 => 'composer dumpautoload --optimize', 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', 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 \\"', 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/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 \\&\\& 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\\"', 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/releases/1234567890 \\&\\& bin/console assetic:dump --env=dev \\"', 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', 10 => 'git checkout master',
); );
// Check total of Executed Commands // Check total of Executed Commands
$this->assertEquals(count($ranCommands), count($testCase)); $this->assertEquals(count($testCase), count($ranCommands));
// Check Generated Commands // Check Generated Commands
foreach ($testCase as $index => $command) { 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() public function testDeploymentWithSkippingTask()
@ -465,8 +470,6 @@ class DeployCommandTest extends TestCase
) )
); );
$runtime->setReleaseId('1234567890');
/** @var AbstractCommand $command */ /** @var AbstractCommand $command */
$command = $application->find('deploy'); $command = $application->find('deploy');
$command->setRuntime($runtime); $command->setRuntime($runtime);
@ -482,23 +485,23 @@ class DeployCommandTest extends TestCase
2 => 'composer install --dev', 2 => 'composer install --dev',
3 => 'composer dumpautoload --optimize', 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', 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 \\"', 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/releases/1234567890 \\&\\& bin/console cache:warmup --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/releases/1234567890 \\&\\& bin/console assets:install --env=dev --symlink --relative web\\"', 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/releases/1234567890 \\&\\& bin/console assetic:dump --env=dev \\"', 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 "*"', 9 => 'git branch | grep "*"',
); );
// Check total of Executed Commands // Check total of Executed Commands
$this->assertEquals(count($ranCommands), count($testCase)); $this->assertEquals(count($testCase), count($ranCommands));
// Check Generated Commands // Check Generated Commands
foreach ($testCase as $index => $command) { foreach ($testCase as $index => $command) {
$this->assertEquals($ranCommands[$index], $command); $this->assertEquals($command, $ranCommands[$index]);
} }
$this->assertTrue(strpos($tester->getDisplay(), 'SKIPPED') !== false); $this->assertTrue(strpos($tester->getDisplay(), 'SKIPPED') !== false);
$this->assertEquals($tester->getStatusCode(), 0); $this->assertEquals(0, $tester->getStatusCode());
} }
} }

13
src/Mage/Tests/Command/BuiltIn/Releases/ListCommandTest.php

@ -1,4 +1,13 @@
<?php <?php
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* 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; namespace Mage\Tests\Command\BuiltIn\Releases;
use Mage\Command\BuiltIn\Releases\ListCommand; use Mage\Command\BuiltIn\Releases\ListCommand;
@ -96,11 +105,11 @@ class ListCommandTest extends TestCase
); );
// Check total of Executed Commands // Check total of Executed Commands
$this->assertEquals(count($ranCommands), count($testCase)); $this->assertEquals(count($testCase), count($ranCommands));
// Check Generated Commands // Check Generated Commands
foreach ($testCase as $index => $command) { foreach ($testCase as $index => $command) {
$this->assertEquals($ranCommands[$index], $command); $this->assertEquals($command, $ranCommands[$index]);
} }
} }
} }

13
src/Mage/Tests/Command/BuiltIn/Releases/RollbackCommandTest.php

@ -1,4 +1,13 @@
<?php <?php
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* 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; namespace Mage\Tests\Command\BuiltIn\Releases;
use Mage\Command\BuiltIn\Releases\RollbackCommand; use Mage\Command\BuiltIn\Releases\RollbackCommand;
@ -96,11 +105,11 @@ class RollbackCommandTest extends TestCase
); );
// Check total of Executed Commands // Check total of Executed Commands
$this->assertEquals(count($ranCommands), count($testCase)); $this->assertEquals(count($testCase), count($ranCommands));
// Check Generated Commands // Check Generated Commands
foreach ($testCase as $index => $command) { foreach ($testCase as $index => $command) {
$this->assertEquals($ranCommands[$index], $command); $this->assertEquals($command, $ranCommands[$index]);
} }
} }
} }

9
src/Mage/Tests/Command/BuiltIn/VersionCommandTest.php

@ -1,4 +1,13 @@
<?php <?php
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mage\Tests\Command\BuiltIn; namespace Mage\Tests\Command\BuiltIn;
use Mage\Command\BuiltIn\VersionCommand; use Mage\Command\BuiltIn\VersionCommand;

15
src/Mage/Tests/MageTestApplication.php

@ -10,23 +10,8 @@
namespace Mage\Tests; 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\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 <andresmontanez@gmail.com>
*/
class MageTestApplication extends Application class MageTestApplication extends Application
{ {
} }

9
src/Mage/Tests/Runtime/ProcessMockup.php

@ -1,4 +1,13 @@
<?php <?php
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mage\Tests\Runtime; namespace Mage\Tests\Runtime;
use Symfony\Component\Process\Process; use Symfony\Component\Process\Process;

9
src/Mage/Tests/Runtime/RuntimeMockup.php

@ -1,4 +1,13 @@
<?php <?php
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mage\Tests\Runtime; namespace Mage\Tests\Runtime;
use Mage\Runtime\Runtime; use Mage\Runtime\Runtime;

145
src/Mage/Tests/Runtime/RuntimeTest.php

@ -0,0 +1,145 @@
<?php
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* 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());
}
}

44
src/Mage/Tests/Task/AbstractTaskTest.php

@ -0,0 +1,44 @@
<?php
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* 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());
}
}
}
}

32
src/Mage/Tests/Task/TestCaseFailTask.php

@ -0,0 +1,32 @@
<?php
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* 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');
}
}

36
src/Mage/Tests/Task/TestCaseTask.php

@ -0,0 +1,36 @@
<?php
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* 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;
}
}

41
src/Mage/Tests/UtilsTest.php

@ -1,4 +1,13 @@
<?php <?php
/*
* This file is part of the Magallanes package.
*
* (c) Andrés Montañez <andres@andresmontanez.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mage\Tests; namespace Mage\Tests;
use Mage\Utils; use Mage\Utils;
@ -10,11 +19,11 @@ class UtilsTest extends TestCase
{ {
public function testStageNames() public function testStageNames()
{ {
$this->assertEquals(Utils::getStageName(Runtime::PRE_DEPLOY), 'Pre Deployment'); $this->assertEquals('Pre Deployment', Utils::getStageName(Runtime::PRE_DEPLOY));
$this->assertEquals(Utils::getStageName(Runtime::ON_DEPLOY), 'On Deployment'); $this->assertEquals('On Deployment', Utils::getStageName(Runtime::ON_DEPLOY));
$this->assertEquals(Utils::getStageName(Runtime::POST_DEPLOY), 'Post Deployment'); $this->assertEquals('Post Deployment', Utils::getStageName(Runtime::POST_DEPLOY));
$this->assertEquals(Utils::getStageName(Runtime::ON_RELEASE), 'On Release'); $this->assertEquals('On Release', Utils::getStageName(Runtime::ON_RELEASE));
$this->assertEquals(Utils::getStageName(Runtime::POST_RELEASE), 'Post Release'); $this->assertEquals('Post Release', Utils::getStageName(Runtime::POST_RELEASE));
} }
public function testReleaseDate() public function testReleaseDate()
@ -24,49 +33,49 @@ class UtilsTest extends TestCase
$this->assertTrue($dateTime instanceof DateTime); $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() public function testTimeDiffs()
{ {
$dateTime = new DateTime(); $dateTime = new DateTime();
$dateTime->modify('-1 second'); $dateTime->modify('-1 second');
$this->assertEquals(Utils::getTimeDiff($dateTime), 'just now'); $this->assertEquals('just now', Utils::getTimeDiff($dateTime));
$dateTime = new DateTime(); $dateTime = new DateTime();
$dateTime->modify('-45 seconds'); $dateTime->modify('-45 seconds');
$this->assertEquals(Utils::getTimeDiff($dateTime), '45 seconds ago'); $this->assertEquals('45 seconds ago', Utils::getTimeDiff($dateTime));
$dateTime = new DateTime(); $dateTime = new DateTime();
$dateTime->modify('-90 seconds'); $dateTime->modify('-90 seconds');
$this->assertEquals(Utils::getTimeDiff($dateTime), 'one minute ago'); $this->assertEquals('one minute ago', Utils::getTimeDiff($dateTime));
$dateTime = new DateTime(); $dateTime = new DateTime();
$dateTime->modify('-30 minutes'); $dateTime->modify('-30 minutes');
$this->assertEquals(Utils::getTimeDiff($dateTime), '30 minutes ago'); $this->assertEquals('30 minutes ago', Utils::getTimeDiff($dateTime));
$dateTime = new DateTime(); $dateTime = new DateTime();
$dateTime->modify('-1 hour'); $dateTime->modify('-1 hour');
$this->assertEquals(Utils::getTimeDiff($dateTime), 'one hour ago'); $this->assertEquals('one hour ago', Utils::getTimeDiff($dateTime));
$dateTime = new DateTime(); $dateTime = new DateTime();
$dateTime->modify('-10 hours'); $dateTime->modify('-10 hours');
$this->assertEquals(Utils::getTimeDiff($dateTime), '10 hours ago'); $this->assertEquals('10 hours ago', Utils::getTimeDiff($dateTime));
$dateTime = new DateTime(); $dateTime = new DateTime();
$dateTime->modify('-1 day'); $dateTime->modify('-1 day');
$this->assertEquals(Utils::getTimeDiff($dateTime), 'one day ago'); $this->assertEquals('one day ago', Utils::getTimeDiff($dateTime));
$dateTime = new DateTime(); $dateTime = new DateTime();
$dateTime->modify('-3 days'); $dateTime->modify('-3 days');
$this->assertEquals(Utils::getTimeDiff($dateTime), '3 days ago'); $this->assertEquals('3 days ago', Utils::getTimeDiff($dateTime));
$dateTime = new DateTime(); $dateTime = new DateTime();
$dateTime->modify('-7 days'); $dateTime->modify('-7 days');
$this->assertEquals(Utils::getTimeDiff($dateTime), 'a week ago'); $this->assertEquals('a week ago', Utils::getTimeDiff($dateTime));
$dateTime = new DateTime(); $dateTime = new DateTime();
$dateTime->modify('-10 days'); $dateTime->modify('-10 days');
$this->assertEquals(Utils::getTimeDiff($dateTime), ''); $this->assertEquals('', Utils::getTimeDiff($dateTime));
} }
} }

Loading…
Cancel
Save