Skip to content

Commit

Permalink
[Nostromo] Add more and tweak Tests
Browse files Browse the repository at this point in the history
  • Loading branch information
andres-montanez committed Jan 1, 2017
1 parent 616258e commit 3c21cfc
Show file tree
Hide file tree
Showing 16 changed files with 389 additions and 68 deletions.
6 changes: 5 additions & 1 deletion src/Mage/Runtime/Runtime.php
Expand Up @@ -31,7 +31,7 @@ class Runtime
/**
* @var array Magallanes configuration
*/
protected $configuration;
protected $configuration = [];

/**
* @var string|null Environment being deployed
Expand Down Expand Up @@ -214,6 +214,10 @@ public function getConfigOptions($key, $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'])) {
return [];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Mage/Task/ErrorException.php
Expand Up @@ -19,7 +19,7 @@
*/
class ErrorException extends Exception
{
public function getTrimmedMessage($maxLength = 80)
public function getTrimmedMessage($maxLength = 60)
{
$message = $this->getMessage();

Expand Down
11 changes: 10 additions & 1 deletion src/Mage/Tests/Command/BuiltIn/Config/DumpCommandTest.php
@@ -1,4 +1,13 @@
<?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;

use Mage\Command\BuiltIn\Config\DumpCommand;
Expand All @@ -22,6 +31,6 @@ public function testConfigDumpTermination()
$tester = new CommandTester($command);
$tester->execute(['command' => $command->getName()]);

$this->assertEquals($tester->getStatusCode(), 0);
$this->assertEquals(0, $tester->getStatusCode());
}
}
@@ -1,4 +1,13 @@
<?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;

use Mage\Command\BuiltIn\Config\EnvironmentsCommand;
Expand Down Expand Up @@ -88,6 +97,6 @@ public function testConfigDumpTermination()
$tester = new CommandTester($command);
$tester->execute(['command' => $command->getName()]);

$this->assertEquals($tester->getStatusCode(), 0);
$this->assertEquals(0, $tester->getStatusCode());
}
}
61 changes: 32 additions & 29 deletions src/Mage/Tests/Command/BuiltIn/DeployCommandTest.php
@@ -1,4 +1,13 @@
<?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;

use Mage\Command\BuiltIn\DeployCommand;
Expand Down Expand Up @@ -118,14 +127,14 @@ public function testDeploymentWithReleasesCommands()
);

// 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()
Expand Down Expand Up @@ -197,16 +206,16 @@ public function testDeploymentWithErrorTaskCommands()
);

// 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()
Expand Down Expand Up @@ -255,8 +264,6 @@ public function testDeploymentWithFailingPostDeployTaskCommands()
)
);

$runtime->setReleaseId('20170101015120');

/** @var AbstractCommand $command */
$command = $application->find('deploy');
$command->setRuntime($runtime);
Expand All @@ -277,16 +284,16 @@ public function testDeploymentWithFailingPostDeployTaskCommands()
);

// 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()
Expand Down Expand Up @@ -359,8 +366,6 @@ public function testDeploymentWithoutReleasesCommands()
)
);

$runtime->setReleaseId('1234567890');

/** @var AbstractCommand $command */
$command = $application->find('deploy');
$command->setRuntime($runtime);
Expand All @@ -377,22 +382,22 @@ public function testDeploymentWithoutReleasesCommands()
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()
Expand Down Expand Up @@ -465,8 +470,6 @@ public function testDeploymentWithSkippingTask()
)
);

$runtime->setReleaseId('1234567890');

/** @var AbstractCommand $command */
$command = $application->find('deploy');
$command->setRuntime($runtime);
Expand All @@ -482,23 +485,23 @@ public function testDeploymentWithSkippingTask()
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());
}
}
13 changes: 11 additions & 2 deletions src/Mage/Tests/Command/BuiltIn/Releases/ListCommandTest.php
@@ -1,4 +1,13 @@
<?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;

use Mage\Command\BuiltIn\Releases\ListCommand;
Expand Down Expand Up @@ -96,11 +105,11 @@ public function testListReleasesCommands()
);

// 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]);
}
}
}
13 changes: 11 additions & 2 deletions src/Mage/Tests/Command/BuiltIn/Releases/RollbackCommandTest.php
@@ -1,4 +1,13 @@
<?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;

use Mage\Command\BuiltIn\Releases\RollbackCommand;
Expand Down Expand Up @@ -96,11 +105,11 @@ public function testRollbackReleaseCommands()
);

// 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]);
}
}
}
9 changes: 9 additions & 0 deletions src/Mage/Tests/Command/BuiltIn/VersionCommandTest.php
@@ -1,4 +1,13 @@
<?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;

use Mage\Command\BuiltIn\VersionCommand;
Expand Down
15 changes: 0 additions & 15 deletions src/Mage/Tests/MageTestApplication.php
Expand Up @@ -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 <andresmontanez@gmail.com>
*/
class MageTestApplication extends Application
{
}
9 changes: 9 additions & 0 deletions src/Mage/Tests/Runtime/ProcessMockup.php
@@ -1,4 +1,13 @@
<?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 Symfony\Component\Process\Process;
Expand Down
9 changes: 9 additions & 0 deletions src/Mage/Tests/Runtime/RuntimeMockup.php
@@ -1,4 +1,13 @@
<?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;
Expand Down

0 comments on commit 3c21cfc

Please sign in to comment.