mirror of https://github.com/hauke68/Magallanes
Andrés Montañez
8 years ago
committed by
GitHub
34 changed files with 1330 additions and 406 deletions
@ -0,0 +1,93 @@ |
|||||||
|
<?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\Task\BuiltIn\Composer; |
||||||
|
|
||||||
|
use Mage\Task\Exception\SkipException; |
||||||
|
use Symfony\Component\Process\Process; |
||||||
|
use Mage\Task\AbstractTask; |
||||||
|
use DateTime; |
||||||
|
|
||||||
|
/** |
||||||
|
* Composer Task - Self update |
||||||
|
* |
||||||
|
* @author Yanick Witschi <https://github.com/Toflar> |
||||||
|
*/ |
||||||
|
class SelfUpdateTask extends AbstractTask |
||||||
|
{ |
||||||
|
public function getName() |
||||||
|
{ |
||||||
|
return 'composer/self-update'; |
||||||
|
} |
||||||
|
|
||||||
|
public function getDescription() |
||||||
|
{ |
||||||
|
return '[Composer] Self Update'; |
||||||
|
} |
||||||
|
|
||||||
|
public function execute() |
||||||
|
{ |
||||||
|
$options = $this->getOptions(); |
||||||
|
$cmdVersion = sprintf('%s --version', $options['path']); |
||||||
|
/** @var Process $process */ |
||||||
|
$process = $this->runtime->runCommand(trim($cmdVersion)); |
||||||
|
if (!$process->isSuccessful()) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
$buildDate = $this->getBuildDate($process->getOutput()); |
||||||
|
if (!$buildDate instanceof DateTime) { |
||||||
|
return false; |
||||||
|
} |
||||||
|
|
||||||
|
$compareDate = $this->getCompareDate(); |
||||||
|
if ($buildDate >= $compareDate) { |
||||||
|
throw new SkipException(); |
||||||
|
} |
||||||
|
|
||||||
|
$cmdUpdate = sprintf('%s self-update', $options['path']); |
||||||
|
/** @var Process $process */ |
||||||
|
$process = $this->runtime->runCommand(trim($cmdUpdate)); |
||||||
|
|
||||||
|
return $process->isSuccessful(); |
||||||
|
} |
||||||
|
|
||||||
|
protected function getBuildDate($output) |
||||||
|
{ |
||||||
|
$buildDate = null; |
||||||
|
$output = explode(PHP_EOL, $output); |
||||||
|
foreach ($output as $row) { |
||||||
|
if (strpos($row, 'Composer version ') === 0) { |
||||||
|
$buildDate = DateTime::createFromFormat('Y-m-d H:i:s', substr(trim($row), -19)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
return $buildDate; |
||||||
|
} |
||||||
|
|
||||||
|
protected function getCompareDate() |
||||||
|
{ |
||||||
|
$options = $this->getOptions(); |
||||||
|
$compareDate = new DateTime(); |
||||||
|
$compareDate->modify(sprintf('now -%d days', $options['days'])); |
||||||
|
return $compareDate; |
||||||
|
} |
||||||
|
|
||||||
|
protected function getOptions() |
||||||
|
{ |
||||||
|
$options = array_merge( |
||||||
|
['path' => 'composer', 'days' => 60], |
||||||
|
$this->runtime->getMergedOption('composer'), |
||||||
|
$this->options |
||||||
|
); |
||||||
|
|
||||||
|
return $options; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,76 @@ |
|||||||
|
<?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\Task\BuiltIn; |
||||||
|
|
||||||
|
use Mage\Task\Exception\ErrorException; |
||||||
|
use Mage\Task\AbstractTask; |
||||||
|
use Symfony\Component\Process\Process; |
||||||
|
|
||||||
|
/** |
||||||
|
* Exec task. Allows you to execute arbitrary commands. |
||||||
|
* |
||||||
|
* @author Yanick Witschi <https://github.com/Toflar> |
||||||
|
*/ |
||||||
|
class ExecTask extends AbstractTask |
||||||
|
{ |
||||||
|
/** |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
public function getName() |
||||||
|
{ |
||||||
|
return 'exec'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return string |
||||||
|
*/ |
||||||
|
public function getDescription() |
||||||
|
{ |
||||||
|
$options = $this->getOptions(); |
||||||
|
|
||||||
|
if ($options['desc']) { |
||||||
|
return '[Exec] ' . $options['desc']; |
||||||
|
} |
||||||
|
|
||||||
|
return '[Exec] Custom command'; |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return bool |
||||||
|
* |
||||||
|
* @throws ErrorException |
||||||
|
*/ |
||||||
|
public function execute() |
||||||
|
{ |
||||||
|
$options = $this->getOptions(); |
||||||
|
|
||||||
|
if (!$options['cmd']) { |
||||||
|
throw new ErrorException('Parameter "cmd" is not defined'); |
||||||
|
} |
||||||
|
|
||||||
|
/** @var Process $process */ |
||||||
|
$process = $this->runtime->runCommand($options['cmd'], $options['timeout']); |
||||||
|
return $process->isSuccessful(); |
||||||
|
} |
||||||
|
|
||||||
|
/** |
||||||
|
* @return array |
||||||
|
*/ |
||||||
|
protected function getOptions() |
||||||
|
{ |
||||||
|
$options = array_merge( |
||||||
|
['cmd' => '', 'desc' => '', 'timeout' => 120], |
||||||
|
$this->options |
||||||
|
); |
||||||
|
|
||||||
|
return $options; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,60 @@ |
|||||||
|
<?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\Task\BuiltIn\FS; |
||||||
|
|
||||||
|
use Symfony\Component\Process\Process; |
||||||
|
use Exception; |
||||||
|
|
||||||
|
/** |
||||||
|
* File System Task - Copy a File |
||||||
|
* |
||||||
|
* @author Marian Bäuerle |
||||||
|
*/ |
||||||
|
class ChangeModeTask extends AbstractFileTask |
||||||
|
{ |
||||||
|
public function getName() |
||||||
|
{ |
||||||
|
return 'fs/chmod'; |
||||||
|
} |
||||||
|
|
||||||
|
public function getDescription() |
||||||
|
{ |
||||||
|
try { |
||||||
|
return sprintf('[FS] Change mode of "%s" to "%s"', $this->getFile('file'), $this->options['mode']); |
||||||
|
} catch (Exception $exception) { |
||||||
|
return '[FS] Chmod [missing parameters]'; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function execute() |
||||||
|
{ |
||||||
|
$file = $this->getFile('file'); |
||||||
|
$mode = $this->options['mode']; |
||||||
|
$flags = $this->options['flags']; |
||||||
|
|
||||||
|
$cmd = sprintf('chmod %s %s "%s"', $flags, $mode, $file); |
||||||
|
|
||||||
|
/** @var Process $process */ |
||||||
|
$process = $this->runtime->runCommand($cmd); |
||||||
|
|
||||||
|
return $process->isSuccessful(); |
||||||
|
} |
||||||
|
|
||||||
|
protected function getParameters() |
||||||
|
{ |
||||||
|
return ['file', 'mode', 'flags']; |
||||||
|
} |
||||||
|
|
||||||
|
public function getDefaults() |
||||||
|
{ |
||||||
|
return ['flags' => null]; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,19 @@ |
|||||||
|
magephp: |
||||||
|
log_dir: /tmp |
||||||
|
composer: |
||||||
|
path: /usr/bin/composer.phar |
||||||
|
environments: |
||||||
|
test: |
||||||
|
composer: |
||||||
|
path: /usr/foobar/composer |
||||||
|
user: tester |
||||||
|
host_path: /var/www/test |
||||||
|
exclude: |
||||||
|
- ./var/cache/* |
||||||
|
- ./var/log/* |
||||||
|
- ./web/app_dev.php |
||||||
|
hosts: |
||||||
|
- testhost |
||||||
|
pre-deploy: |
||||||
|
- composer/install: { flags: '--prefer-source' } |
||||||
|
- composer/dump-autoload: { flags: '--no-scripts' } |
@ -0,0 +1,174 @@ |
|||||||
|
<?php |
||||||
|
|
||||||
|
namespace Mage\Tests\Task\BuiltIn\Composer; |
||||||
|
|
||||||
|
use Mage\Tests\Runtime\RuntimeMockup; |
||||||
|
use Mage\Task\BuiltIn\Composer\SelfUpdateTask; |
||||||
|
use Mage\Task\Exception\SkipException; |
||||||
|
use Exception; |
||||||
|
use PHPUnit_Framework_TestCase as TestCase; |
||||||
|
|
||||||
|
class SelfUpdateTaskTest extends TestCase |
||||||
|
{ |
||||||
|
public function testSelfUpdateTask() |
||||||
|
{ |
||||||
|
$runtime = new RuntimeMockup(); |
||||||
|
$runtime->setConfiguration(['environments' => ['test' => []]]); |
||||||
|
$runtime->setEnvironment('test'); |
||||||
|
|
||||||
|
$task = new SelfUpdateTask(); |
||||||
|
$task->setOptions(['path' => 'composer']); |
||||||
|
$task->setRuntime($runtime); |
||||||
|
$this->assertEquals('[Composer] Self Update', $task->getDescription()); |
||||||
|
|
||||||
|
try { |
||||||
|
$task->execute(); |
||||||
|
} catch (Exception $exception) { |
||||||
|
$this->assertTrue($exception instanceof SkipException, 'Update should been skipped'); |
||||||
|
} |
||||||
|
|
||||||
|
$ranCommands = $runtime->getRanCommands(); |
||||||
|
$testCase = array( |
||||||
|
0 => 'composer --version', |
||||||
|
); |
||||||
|
|
||||||
|
// Check total of Executed Commands |
||||||
|
$this->assertEquals(count($testCase), count($ranCommands)); |
||||||
|
|
||||||
|
// Check Generated Commands |
||||||
|
foreach ($testCase as $index => $command) { |
||||||
|
$this->assertEquals($command, $ranCommands[$index]); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function testSelfUpdateAsRootTask() |
||||||
|
{ |
||||||
|
$runtime = new RuntimeMockup(); |
||||||
|
$runtime->setConfiguration(['environments' => ['test' => []]]); |
||||||
|
$runtime->setEnvironment('test'); |
||||||
|
|
||||||
|
$task = new SelfUpdateTask(); |
||||||
|
$task->setOptions(['path' => './composer']); |
||||||
|
$task->setRuntime($runtime); |
||||||
|
|
||||||
|
try { |
||||||
|
$task->execute(); |
||||||
|
} catch (Exception $exception) { |
||||||
|
$this->assertTrue($exception instanceof SkipException, 'Update should been skipped'); |
||||||
|
} |
||||||
|
|
||||||
|
$ranCommands = $runtime->getRanCommands(); |
||||||
|
$testCase = array( |
||||||
|
0 => './composer --version', |
||||||
|
); |
||||||
|
|
||||||
|
// Check total of Executed Commands |
||||||
|
$this->assertEquals(count($testCase), count($ranCommands)); |
||||||
|
|
||||||
|
// Check Generated Commands |
||||||
|
foreach ($testCase as $index => $command) { |
||||||
|
$this->assertEquals($command, $ranCommands[$index]); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function testSelfUpdateMustUpdateTask() |
||||||
|
{ |
||||||
|
$runtime = new RuntimeMockup(); |
||||||
|
$runtime->setConfiguration(['environments' => ['test' => []]]); |
||||||
|
$runtime->setEnvironment('test'); |
||||||
|
|
||||||
|
$task = new SelfUpdateTask(); |
||||||
|
$task->setOptions(['path' => 'composer.phar']); |
||||||
|
$task->setRuntime($runtime); |
||||||
|
|
||||||
|
try { |
||||||
|
$result = $task->execute(); |
||||||
|
$this->assertTrue($result, 'Result should be successful'); |
||||||
|
} catch (Exception $exception) { |
||||||
|
if ($exception instanceof SkipException) { |
||||||
|
$this->assertTrue(false, 'Update should not have been skipped'); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
$ranCommands = $runtime->getRanCommands(); |
||||||
|
$testCase = array( |
||||||
|
0 => 'composer.phar --version', |
||||||
|
1 => 'composer.phar self-update', |
||||||
|
); |
||||||
|
|
||||||
|
// Check total of Executed Commands |
||||||
|
$this->assertEquals(count($testCase), count($ranCommands)); |
||||||
|
|
||||||
|
// Check Generated Commands |
||||||
|
foreach ($testCase as $index => $command) { |
||||||
|
$this->assertEquals($command, $ranCommands[$index]); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function testSelfUpdateWrongOutputTask() |
||||||
|
{ |
||||||
|
$runtime = new RuntimeMockup(); |
||||||
|
$runtime->setConfiguration(['environments' => ['test' => []]]); |
||||||
|
$runtime->setEnvironment('test'); |
||||||
|
|
||||||
|
$task = new SelfUpdateTask(); |
||||||
|
$task->setOptions(['path' => 'php composer']); |
||||||
|
$task->setRuntime($runtime); |
||||||
|
|
||||||
|
try { |
||||||
|
$result = $task->execute(); |
||||||
|
$this->assertFalse($result, 'Result should be failure'); |
||||||
|
} catch (Exception $exception) { |
||||||
|
if ($exception instanceof SkipException) { |
||||||
|
$this->assertTrue(false, 'Update should not have been skipped'); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
$ranCommands = $runtime->getRanCommands(); |
||||||
|
$testCase = array( |
||||||
|
0 => 'php composer --version', |
||||||
|
); |
||||||
|
|
||||||
|
// Check total of Executed Commands |
||||||
|
$this->assertEquals(count($testCase), count($ranCommands)); |
||||||
|
|
||||||
|
// Check Generated Commands |
||||||
|
foreach ($testCase as $index => $command) { |
||||||
|
$this->assertEquals($command, $ranCommands[$index]); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function testSelfUpdateFailExecTask() |
||||||
|
{ |
||||||
|
$runtime = new RuntimeMockup(); |
||||||
|
$runtime->setConfiguration(['environments' => ['test' => []]]); |
||||||
|
$runtime->setEnvironment('test'); |
||||||
|
|
||||||
|
$task = new SelfUpdateTask(); |
||||||
|
$task->setOptions(['path' => 'composer']); |
||||||
|
$task->setRuntime($runtime); |
||||||
|
$runtime->forceFail('composer --version'); |
||||||
|
|
||||||
|
try { |
||||||
|
$result = $task->execute(); |
||||||
|
$this->assertFalse($result, 'Result should be failure'); |
||||||
|
} catch (Exception $exception) { |
||||||
|
if ($exception instanceof SkipException) { |
||||||
|
$this->assertTrue(false, 'Update should not have been skipped'); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
$ranCommands = $runtime->getRanCommands(); |
||||||
|
$testCase = array( |
||||||
|
0 => 'composer --version', |
||||||
|
); |
||||||
|
|
||||||
|
// Check total of Executed Commands |
||||||
|
$this->assertEquals(count($testCase), count($ranCommands)); |
||||||
|
|
||||||
|
// Check Generated Commands |
||||||
|
foreach ($testCase as $index => $command) { |
||||||
|
$this->assertEquals($command, $ranCommands[$index]); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,97 @@ |
|||||||
|
<?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\BuiltIn; |
||||||
|
|
||||||
|
use Mage\Task\Exception\ErrorException; |
||||||
|
use Mage\Task\BuiltIn\ExecTask; |
||||||
|
use Exception; |
||||||
|
use Mage\Tests\Runtime\RuntimeMockup; |
||||||
|
use PHPUnit_Framework_TestCase as TestCase; |
||||||
|
|
||||||
|
class ExecTest extends TestCase |
||||||
|
{ |
||||||
|
public function testSimpleCommand() |
||||||
|
{ |
||||||
|
$runtime = new RuntimeMockup(); |
||||||
|
$runtime->setConfiguration(['environments' => ['test' => []]]); |
||||||
|
$runtime->setEnvironment('test'); |
||||||
|
|
||||||
|
$task = new ExecTask(); |
||||||
|
$task->setOptions(['cmd' => 'ls -l', 'desc' => 'Loading docker']); |
||||||
|
$task->setRuntime($runtime); |
||||||
|
|
||||||
|
$this->assertContains('[Exec] Loading docker', $task->getDescription()); |
||||||
|
$task->execute(); |
||||||
|
|
||||||
|
$ranCommands = $runtime->getRanCommands(); |
||||||
|
|
||||||
|
$testCase = array( |
||||||
|
0 => 'ls -l', |
||||||
|
); |
||||||
|
|
||||||
|
// Check total of Executed Commands |
||||||
|
$this->assertEquals(count($testCase), count($ranCommands)); |
||||||
|
|
||||||
|
// Check Generated Commands |
||||||
|
foreach ($testCase as $index => $command) { |
||||||
|
$this->assertEquals($command, $ranCommands[$index]); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function testCommandWithoutDescription() |
||||||
|
{ |
||||||
|
$runtime = new RuntimeMockup(); |
||||||
|
$runtime->setConfiguration(['environments' => ['test' => []]]); |
||||||
|
$runtime->setEnvironment('test'); |
||||||
|
|
||||||
|
$task = new ExecTask(); |
||||||
|
$task->setOptions(['cmd' => 'ls -la']); |
||||||
|
$task->setRuntime($runtime); |
||||||
|
|
||||||
|
$this->assertContains('[Exec] Custom command', $task->getDescription()); |
||||||
|
$task->execute(); |
||||||
|
|
||||||
|
$ranCommands = $runtime->getRanCommands(); |
||||||
|
|
||||||
|
$testCase = array( |
||||||
|
0 => 'ls -la', |
||||||
|
); |
||||||
|
|
||||||
|
// Check total of Executed Commands |
||||||
|
$this->assertEquals(count($testCase), count($ranCommands)); |
||||||
|
|
||||||
|
// Check Generated Commands |
||||||
|
foreach ($testCase as $index => $command) { |
||||||
|
$this->assertEquals($command, $ranCommands[$index]); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function testWithoutCommand() |
||||||
|
{ |
||||||
|
$runtime = new RuntimeMockup(); |
||||||
|
$runtime->setConfiguration(['environments' => ['test' => []]]); |
||||||
|
$runtime->setEnvironment('test'); |
||||||
|
|
||||||
|
$task = new ExecTask(); |
||||||
|
$task->setOptions(['desc' => 'Loading docker']); |
||||||
|
$task->setRuntime($runtime); |
||||||
|
|
||||||
|
$this->assertContains('[Exec] Loading docker', $task->getDescription()); |
||||||
|
|
||||||
|
try { |
||||||
|
$task->execute(); |
||||||
|
$this->assertTrue(false, 'Task did not failed'); |
||||||
|
} catch (Exception $exception) { |
||||||
|
$this->assertTrue($exception instanceof ErrorException); |
||||||
|
$this->assertEquals('Parameter "cmd" is not defined', $exception->getMessage()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,127 @@ |
|||||||
|
<?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\BuiltIn\FileSystem; |
||||||
|
|
||||||
|
use Mage\Task\Exception\ErrorException; |
||||||
|
use Mage\Task\BuiltIn\FS\ChangeModeTask; |
||||||
|
use Exception; |
||||||
|
use Mage\Tests\Runtime\RuntimeMockup; |
||||||
|
use PHPUnit_Framework_TestCase as TestCase; |
||||||
|
|
||||||
|
class ChangeModeTest extends TestCase |
||||||
|
{ |
||||||
|
public function testChangeModeTask() |
||||||
|
{ |
||||||
|
$runtime = new RuntimeMockup(); |
||||||
|
$runtime->setConfiguration(['environments' => ['test' => []]]); |
||||||
|
$runtime->setEnvironment('test'); |
||||||
|
|
||||||
|
$task = new ChangeModeTask(); |
||||||
|
$task->setOptions(['file' => 'a.txt', 'flags' => '-R', 'mode' => 'o+w']); |
||||||
|
$task->setRuntime($runtime); |
||||||
|
|
||||||
|
$this->assertContains('a.txt', $task->getDescription()); |
||||||
|
$this->assertContains('o+w', $task->getDescription()); |
||||||
|
$task->execute(); |
||||||
|
|
||||||
|
$ranCommands = $runtime->getRanCommands(); |
||||||
|
|
||||||
|
$testCase = array( |
||||||
|
0 => 'chmod -R o+w "a.txt"', |
||||||
|
); |
||||||
|
|
||||||
|
// Check total of Executed Commands |
||||||
|
$this->assertEquals(count($testCase), count($ranCommands)); |
||||||
|
|
||||||
|
// Check Generated Commands |
||||||
|
foreach ($testCase as $index => $command) { |
||||||
|
$this->assertEquals($command, $ranCommands[$index]); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function testChangeModeTaskWithoutFlags() |
||||||
|
{ |
||||||
|
$runtime = new RuntimeMockup(); |
||||||
|
$runtime->setConfiguration(['environments' => ['test' => []]]); |
||||||
|
$runtime->setEnvironment('test'); |
||||||
|
|
||||||
|
$task = new ChangeModeTask(); |
||||||
|
$task->setOptions(['file' => 'a.txt', 'mode' => 'o+w']); |
||||||
|
$task->setRuntime($runtime); |
||||||
|
|
||||||
|
$this->assertContains('a.txt', $task->getDescription()); |
||||||
|
$this->assertContains('o+w', $task->getDescription()); |
||||||
|
$task->execute(); |
||||||
|
|
||||||
|
$ranCommands = $runtime->getRanCommands(); |
||||||
|
|
||||||
|
$testCase = array( |
||||||
|
0 => 'chmod o+w "a.txt"', |
||||||
|
); |
||||||
|
|
||||||
|
// Check total of Executed Commands |
||||||
|
$this->assertEquals(count($testCase), count($ranCommands)); |
||||||
|
|
||||||
|
// Check Generated Commands |
||||||
|
foreach ($testCase as $index => $command) { |
||||||
|
$this->assertEquals($command, $ranCommands[$index]); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function testChangeModeReplaceTask() |
||||||
|
{ |
||||||
|
$runtime = new RuntimeMockup(); |
||||||
|
$runtime->setConfiguration(['environments' => ['test' => []]]); |
||||||
|
$runtime->setEnvironment('test'); |
||||||
|
|
||||||
|
$task = new ChangeModeTask(); |
||||||
|
$task->setOptions(['file' => '%environment%.txt', 'flags' => '-R', 'mode' => 'o+w']); |
||||||
|
$task->setRuntime($runtime); |
||||||
|
|
||||||
|
$this->assertContains('test.txt', $task->getDescription()); |
||||||
|
$this->assertContains('o+w', $task->getDescription()); |
||||||
|
$task->execute(); |
||||||
|
|
||||||
|
$ranCommands = $runtime->getRanCommands(); |
||||||
|
|
||||||
|
$testCase = array( |
||||||
|
0 => 'chmod -R o+w "test.txt"', |
||||||
|
); |
||||||
|
|
||||||
|
// Check total of Executed Commands |
||||||
|
$this->assertEquals(count($testCase), count($ranCommands)); |
||||||
|
|
||||||
|
// Check Generated Commands |
||||||
|
foreach ($testCase as $index => $command) { |
||||||
|
$this->assertEquals($command, $ranCommands[$index]); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function testChangeModeBadOptionsTask() |
||||||
|
{ |
||||||
|
$runtime = new RuntimeMockup(); |
||||||
|
$runtime->setConfiguration(['environments' => ['test' => []]]); |
||||||
|
$runtime->setEnvironment('test'); |
||||||
|
|
||||||
|
$task = new ChangeModeTask(); |
||||||
|
$task->setOptions(['from' => 'a.txt', 'flags' => '-R', 'mode' => 'o+w']); |
||||||
|
$task->setRuntime($runtime); |
||||||
|
|
||||||
|
try { |
||||||
|
$this->assertContains('[missing parameters]', $task->getDescription()); |
||||||
|
$task->execute(); |
||||||
|
$this->assertTrue(false, 'Task should have raised an exception'); |
||||||
|
} catch (Exception $exception) { |
||||||
|
$this->assertTrue($exception instanceof ErrorException); |
||||||
|
$this->assertEquals('Parameter "file" is not defined', $exception->getMessage()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,158 @@ |
|||||||
|
<?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\BuiltIn\FileSystem; |
||||||
|
|
||||||
|
use Mage\Task\Exception\ErrorException; |
||||||
|
use Mage\Task\BuiltIn\FS\CopyTask; |
||||||
|
use Exception; |
||||||
|
use Mage\Tests\Runtime\RuntimeMockup; |
||||||
|
use PHPUnit_Framework_TestCase as TestCase; |
||||||
|
|
||||||
|
class CopyTaskTest extends TestCase |
||||||
|
{ |
||||||
|
public function testCopyTask() |
||||||
|
{ |
||||||
|
$runtime = new RuntimeMockup(); |
||||||
|
$runtime->setConfiguration(['environments' => ['test' => []]]); |
||||||
|
$runtime->setEnvironment('test'); |
||||||
|
|
||||||
|
$task = new CopyTask(); |
||||||
|
$task->setOptions(['from' => 'a.txt', 'to' => 'b.txt']); |
||||||
|
$task->setRuntime($runtime); |
||||||
|
|
||||||
|
$this->assertContains('a.txt', $task->getDescription()); |
||||||
|
$this->assertContains('b.txt', $task->getDescription()); |
||||||
|
$task->execute(); |
||||||
|
|
||||||
|
$ranCommands = $runtime->getRanCommands(); |
||||||
|
|
||||||
|
$testCase = array( |
||||||
|
0 => 'cp -p "a.txt" "b.txt"', |
||||||
|
); |
||||||
|
|
||||||
|
// Check total of Executed Commands |
||||||
|
$this->assertEquals(count($testCase), count($ranCommands)); |
||||||
|
|
||||||
|
// Check Generated Commands |
||||||
|
foreach ($testCase as $index => $command) { |
||||||
|
$this->assertEquals($command, $ranCommands[$index]); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function testCopyTaskWithFlags() |
||||||
|
{ |
||||||
|
$runtime = new RuntimeMockup(); |
||||||
|
$runtime->setConfiguration(['environments' => ['test' => []]]); |
||||||
|
$runtime->setEnvironment('test'); |
||||||
|
|
||||||
|
$task = new CopyTask(); |
||||||
|
$task->setOptions(['from' => 'a.txt', 'to' => 'b.txt', 'flags' => '-rp']); |
||||||
|
$task->setRuntime($runtime); |
||||||
|
|
||||||
|
$this->assertContains('a.txt', $task->getDescription()); |
||||||
|
$this->assertContains('b.txt', $task->getDescription()); |
||||||
|
$task->execute(); |
||||||
|
|
||||||
|
$ranCommands = $runtime->getRanCommands(); |
||||||
|
|
||||||
|
$testCase = array( |
||||||
|
0 => 'cp -rp "a.txt" "b.txt"', |
||||||
|
); |
||||||
|
|
||||||
|
// Check total of Executed Commands |
||||||
|
$this->assertEquals(count($testCase), count($ranCommands)); |
||||||
|
|
||||||
|
// Check Generated Commands |
||||||
|
foreach ($testCase as $index => $command) { |
||||||
|
$this->assertEquals($command, $ranCommands[$index]); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function testCopyReplaceTask() |
||||||
|
{ |
||||||
|
$runtime = new RuntimeMockup(); |
||||||
|
$runtime->setConfiguration(['environments' => ['test' => []]]); |
||||||
|
$runtime->setEnvironment('test'); |
||||||
|
|
||||||
|
$task = new CopyTask(); |
||||||
|
$task->setOptions(['from' => '%environment%.txt', 'to' => 'b.txt']); |
||||||
|
$task->setRuntime($runtime); |
||||||
|
|
||||||
|
$this->assertContains('test.txt', $task->getDescription()); |
||||||
|
$this->assertContains('b.txt', $task->getDescription()); |
||||||
|
$task->execute(); |
||||||
|
|
||||||
|
$ranCommands = $runtime->getRanCommands(); |
||||||
|
|
||||||
|
$testCase = array( |
||||||
|
0 => 'cp -p "test.txt" "b.txt"', |
||||||
|
); |
||||||
|
|
||||||
|
// Check total of Executed Commands |
||||||
|
$this->assertEquals(count($testCase), count($ranCommands)); |
||||||
|
|
||||||
|
// Check Generated Commands |
||||||
|
foreach ($testCase as $index => $command) { |
||||||
|
$this->assertEquals($command, $ranCommands[$index]); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function testCopyMultipleReplaceTask() |
||||||
|
{ |
||||||
|
$runtime = new RuntimeMockup(); |
||||||
|
$runtime->setConfiguration(['environments' => ['test' => []]]); |
||||||
|
$runtime->setEnvironment('test'); |
||||||
|
$runtime->setReleaseId('1234'); |
||||||
|
$runtime->setWorkingHost('localhost'); |
||||||
|
|
||||||
|
$task = new CopyTask(); |
||||||
|
$task->setOptions(['from' => '%host%.txt', 'to' => '%release%.yml']); |
||||||
|
$task->setRuntime($runtime); |
||||||
|
|
||||||
|
$this->assertContains('localhost.txt', $task->getDescription()); |
||||||
|
$this->assertContains('1234.yml', $task->getDescription()); |
||||||
|
$task->execute(); |
||||||
|
|
||||||
|
$ranCommands = $runtime->getRanCommands(); |
||||||
|
|
||||||
|
$testCase = array( |
||||||
|
0 => 'cp -p "localhost.txt" "1234.yml"', |
||||||
|
); |
||||||
|
|
||||||
|
// Check total of Executed Commands |
||||||
|
$this->assertEquals(count($testCase), count($ranCommands)); |
||||||
|
|
||||||
|
// Check Generated Commands |
||||||
|
foreach ($testCase as $index => $command) { |
||||||
|
$this->assertEquals($command, $ranCommands[$index]); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function testCopyBadOptionsTask() |
||||||
|
{ |
||||||
|
$runtime = new RuntimeMockup(); |
||||||
|
$runtime->setConfiguration(['environments' => ['test' => []]]); |
||||||
|
$runtime->setEnvironment('test'); |
||||||
|
|
||||||
|
$task = new CopyTask(); |
||||||
|
$task->setOptions(['form' => 'a.txt', 'to' => 'b.txt']); |
||||||
|
$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 ErrorException); |
||||||
|
$this->assertEquals('Parameter "from" is not defined', $exception->getMessage()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,127 @@ |
|||||||
|
<?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\BuiltIn\FileSystem; |
||||||
|
|
||||||
|
use Mage\Task\Exception\ErrorException; |
||||||
|
use Mage\Task\BuiltIn\FS\LinkTask; |
||||||
|
use Exception; |
||||||
|
use Mage\Tests\Runtime\RuntimeMockup; |
||||||
|
use PHPUnit_Framework_TestCase as TestCase; |
||||||
|
|
||||||
|
class LinkTaskTest extends TestCase |
||||||
|
{ |
||||||
|
public function testLinkTask() |
||||||
|
{ |
||||||
|
$runtime = new RuntimeMockup(); |
||||||
|
$runtime->setConfiguration(['environments' => ['test' => []]]); |
||||||
|
$runtime->setEnvironment('test'); |
||||||
|
|
||||||
|
$task = new LinkTask(); |
||||||
|
$task->setOptions(['from' => 'a.txt', 'to' => 'b.txt']); |
||||||
|
$task->setRuntime($runtime); |
||||||
|
|
||||||
|
$this->assertContains('a.txt', $task->getDescription()); |
||||||
|
$this->assertContains('b.txt', $task->getDescription()); |
||||||
|
$task->execute(); |
||||||
|
|
||||||
|
$ranCommands = $runtime->getRanCommands(); |
||||||
|
|
||||||
|
$testCase = array( |
||||||
|
0 => 'ln -snf "a.txt" "b.txt"', |
||||||
|
); |
||||||
|
|
||||||
|
// Check total of Executed Commands |
||||||
|
$this->assertEquals(count($testCase), count($ranCommands)); |
||||||
|
|
||||||
|
// Check Generated Commands |
||||||
|
foreach ($testCase as $index => $command) { |
||||||
|
$this->assertEquals($command, $ranCommands[$index]); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function testLinkTaskWithFlags() |
||||||
|
{ |
||||||
|
$runtime = new RuntimeMockup(); |
||||||
|
$runtime->setConfiguration(['environments' => ['test' => []]]); |
||||||
|
$runtime->setEnvironment('test'); |
||||||
|
|
||||||
|
$task = new LinkTask(); |
||||||
|
$task->setOptions(['from' => 'a.txt', 'to' => 'b.txt', 'flags' => '-P']); |
||||||
|
$task->setRuntime($runtime); |
||||||
|
|
||||||
|
$this->assertContains('a.txt', $task->getDescription()); |
||||||
|
$this->assertContains('b.txt', $task->getDescription()); |
||||||
|
$task->execute(); |
||||||
|
|
||||||
|
$ranCommands = $runtime->getRanCommands(); |
||||||
|
|
||||||
|
$testCase = array( |
||||||
|
0 => 'ln -P "a.txt" "b.txt"', |
||||||
|
); |
||||||
|
|
||||||
|
// Check total of Executed Commands |
||||||
|
$this->assertEquals(count($testCase), count($ranCommands)); |
||||||
|
|
||||||
|
// Check Generated Commands |
||||||
|
foreach ($testCase as $index => $command) { |
||||||
|
$this->assertEquals($command, $ranCommands[$index]); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function testLinkReplaceTask() |
||||||
|
{ |
||||||
|
$runtime = new RuntimeMockup(); |
||||||
|
$runtime->setConfiguration(['environments' => ['test' => []]]); |
||||||
|
$runtime->setEnvironment('test'); |
||||||
|
|
||||||
|
$task = new LinkTask(); |
||||||
|
$task->setOptions(['from' => '%environment%.txt', 'to' => 'b.txt']); |
||||||
|
$task->setRuntime($runtime); |
||||||
|
|
||||||
|
$this->assertContains('test.txt', $task->getDescription()); |
||||||
|
$this->assertContains('b.txt', $task->getDescription()); |
||||||
|
$task->execute(); |
||||||
|
|
||||||
|
$ranCommands = $runtime->getRanCommands(); |
||||||
|
|
||||||
|
$testCase = array( |
||||||
|
0 => 'ln -snf "test.txt" "b.txt"', |
||||||
|
); |
||||||
|
|
||||||
|
// Check total of Executed Commands |
||||||
|
$this->assertEquals(count($testCase), count($ranCommands)); |
||||||
|
|
||||||
|
// Check Generated Commands |
||||||
|
foreach ($testCase as $index => $command) { |
||||||
|
$this->assertEquals($command, $ranCommands[$index]); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function testLinkBadOptionsTask() |
||||||
|
{ |
||||||
|
$runtime = new RuntimeMockup(); |
||||||
|
$runtime->setConfiguration(['environments' => ['test' => []]]); |
||||||
|
$runtime->setEnvironment('test'); |
||||||
|
|
||||||
|
$task = new LinkTask(); |
||||||
|
$task->setOptions(['form' => 'a.txt', 'to' => 'b.txt']); |
||||||
|
$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 ErrorException); |
||||||
|
$this->assertEquals('Parameter "from" is not defined', $exception->getMessage()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,127 @@ |
|||||||
|
<?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\BuiltIn\FileSystem; |
||||||
|
|
||||||
|
use Mage\Task\Exception\ErrorException; |
||||||
|
use Mage\Task\BuiltIn\FS\MoveTask; |
||||||
|
use Exception; |
||||||
|
use Mage\Tests\Runtime\RuntimeMockup; |
||||||
|
use PHPUnit_Framework_TestCase as TestCase; |
||||||
|
|
||||||
|
class MoveTaskTest extends TestCase |
||||||
|
{ |
||||||
|
public function testMoveTask() |
||||||
|
{ |
||||||
|
$runtime = new RuntimeMockup(); |
||||||
|
$runtime->setConfiguration(['environments' => ['test' => []]]); |
||||||
|
$runtime->setEnvironment('test'); |
||||||
|
|
||||||
|
$task = new MoveTask(); |
||||||
|
$task->setOptions(['from' => 'a.txt', 'to' => 'b.txt']); |
||||||
|
$task->setRuntime($runtime); |
||||||
|
|
||||||
|
$this->assertContains('a.txt', $task->getDescription()); |
||||||
|
$this->assertContains('b.txt', $task->getDescription()); |
||||||
|
$task->execute(); |
||||||
|
|
||||||
|
$ranCommands = $runtime->getRanCommands(); |
||||||
|
|
||||||
|
$testCase = array( |
||||||
|
0 => 'mv "a.txt" "b.txt"', |
||||||
|
); |
||||||
|
|
||||||
|
// Check total of Executed Commands |
||||||
|
$this->assertEquals(count($testCase), count($ranCommands)); |
||||||
|
|
||||||
|
// Check Generated Commands |
||||||
|
foreach ($testCase as $index => $command) { |
||||||
|
$this->assertEquals($command, $ranCommands[$index]); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function testMoveWithFlagsTask() |
||||||
|
{ |
||||||
|
$runtime = new RuntimeMockup(); |
||||||
|
$runtime->setConfiguration(['environments' => ['test' => []]]); |
||||||
|
$runtime->setEnvironment('test'); |
||||||
|
|
||||||
|
$task = new MoveTask(); |
||||||
|
$task->setOptions(['from' => 'a.txt', 'to' => 'b.txt', 'flags' => '-n']); |
||||||
|
$task->setRuntime($runtime); |
||||||
|
|
||||||
|
$this->assertContains('a.txt', $task->getDescription()); |
||||||
|
$this->assertContains('b.txt', $task->getDescription()); |
||||||
|
$task->execute(); |
||||||
|
|
||||||
|
$ranCommands = $runtime->getRanCommands(); |
||||||
|
|
||||||
|
$testCase = array( |
||||||
|
0 => 'mv -n "a.txt" "b.txt"', |
||||||
|
); |
||||||
|
|
||||||
|
// Check total of Executed Commands |
||||||
|
$this->assertEquals(count($testCase), count($ranCommands)); |
||||||
|
|
||||||
|
// Check Generated Commands |
||||||
|
foreach ($testCase as $index => $command) { |
||||||
|
$this->assertEquals($command, $ranCommands[$index]); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function testMoveReplaceTask() |
||||||
|
{ |
||||||
|
$runtime = new RuntimeMockup(); |
||||||
|
$runtime->setConfiguration(['environments' => ['test' => []]]); |
||||||
|
$runtime->setEnvironment('test'); |
||||||
|
|
||||||
|
$task = new MoveTask(); |
||||||
|
$task->setOptions(['from' => '%environment%.txt', 'to' => 'b.txt']); |
||||||
|
$task->setRuntime($runtime); |
||||||
|
|
||||||
|
$this->assertContains('test.txt', $task->getDescription()); |
||||||
|
$this->assertContains('b.txt', $task->getDescription()); |
||||||
|
$task->execute(); |
||||||
|
|
||||||
|
$ranCommands = $runtime->getRanCommands(); |
||||||
|
|
||||||
|
$testCase = array( |
||||||
|
0 => 'mv "test.txt" "b.txt"', |
||||||
|
); |
||||||
|
|
||||||
|
// Check total of Executed Commands |
||||||
|
$this->assertEquals(count($testCase), count($ranCommands)); |
||||||
|
|
||||||
|
// Check Generated Commands |
||||||
|
foreach ($testCase as $index => $command) { |
||||||
|
$this->assertEquals($command, $ranCommands[$index]); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function testMoveBadOptionsTask() |
||||||
|
{ |
||||||
|
$runtime = new RuntimeMockup(); |
||||||
|
$runtime->setConfiguration(['environments' => ['test' => []]]); |
||||||
|
$runtime->setEnvironment('test'); |
||||||
|
|
||||||
|
$task = new MoveTask(); |
||||||
|
$task->setOptions(['form' => 'a.txt', 'to' => 'b.txt']); |
||||||
|
$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 ErrorException); |
||||||
|
$this->assertEquals('Parameter "from" is not defined', $exception->getMessage()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,124 @@ |
|||||||
|
<?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\BuiltIn\FileSystem; |
||||||
|
|
||||||
|
use Mage\Task\Exception\ErrorException; |
||||||
|
use Mage\Task\BuiltIn\FS\RemoveTask; |
||||||
|
use Exception; |
||||||
|
use Mage\Tests\Runtime\RuntimeMockup; |
||||||
|
use PHPUnit_Framework_TestCase as TestCase; |
||||||
|
|
||||||
|
class RemoveTaskTest extends TestCase |
||||||
|
{ |
||||||
|
public function testRemoveTask() |
||||||
|
{ |
||||||
|
$runtime = new RuntimeMockup(); |
||||||
|
$runtime->setConfiguration(['environments' => ['test' => []]]); |
||||||
|
$runtime->setEnvironment('test'); |
||||||
|
|
||||||
|
$task = new RemoveTask(); |
||||||
|
$task->setOptions(['file' => 'a.txt']); |
||||||
|
$task->setRuntime($runtime); |
||||||
|
|
||||||
|
$this->assertContains('a.txt', $task->getDescription()); |
||||||
|
$task->execute(); |
||||||
|
|
||||||
|
$ranCommands = $runtime->getRanCommands(); |
||||||
|
|
||||||
|
$testCase = array( |
||||||
|
0 => 'rm "a.txt"', |
||||||
|
); |
||||||
|
|
||||||
|
// Check total of Executed Commands |
||||||
|
$this->assertEquals(count($testCase), count($ranCommands)); |
||||||
|
|
||||||
|
// Check Generated Commands |
||||||
|
foreach ($testCase as $index => $command) { |
||||||
|
$this->assertEquals($command, $ranCommands[$index]); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function testRemoveWithFlagsTask() |
||||||
|
{ |
||||||
|
$runtime = new RuntimeMockup(); |
||||||
|
$runtime->setConfiguration(['environments' => ['test' => []]]); |
||||||
|
$runtime->setEnvironment('test'); |
||||||
|
|
||||||
|
$task = new RemoveTask(); |
||||||
|
$task->setOptions(['file' => 'a.txt', 'flags' => '-fr']); |
||||||
|
$task->setRuntime($runtime); |
||||||
|
|
||||||
|
$this->assertContains('a.txt', $task->getDescription()); |
||||||
|
$task->execute(); |
||||||
|
|
||||||
|
$ranCommands = $runtime->getRanCommands(); |
||||||
|
|
||||||
|
$testCase = array( |
||||||
|
0 => 'rm -fr "a.txt"', |
||||||
|
); |
||||||
|
|
||||||
|
// Check total of Executed Commands |
||||||
|
$this->assertEquals(count($testCase), count($ranCommands)); |
||||||
|
|
||||||
|
// Check Generated Commands |
||||||
|
foreach ($testCase as $index => $command) { |
||||||
|
$this->assertEquals($command, $ranCommands[$index]); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function testRemoveReplaceTask() |
||||||
|
{ |
||||||
|
$runtime = new RuntimeMockup(); |
||||||
|
$runtime->setConfiguration(['environments' => ['test' => []]]); |
||||||
|
$runtime->setEnvironment('test'); |
||||||
|
|
||||||
|
$task = new RemoveTask(); |
||||||
|
$task->setOptions(['file' => '%environment%.txt']); |
||||||
|
$task->setRuntime($runtime); |
||||||
|
|
||||||
|
$this->assertContains('test.txt', $task->getDescription()); |
||||||
|
$task->execute(); |
||||||
|
|
||||||
|
$ranCommands = $runtime->getRanCommands(); |
||||||
|
|
||||||
|
$testCase = array( |
||||||
|
0 => 'rm "test.txt"', |
||||||
|
); |
||||||
|
|
||||||
|
// Check total of Executed Commands |
||||||
|
$this->assertEquals(count($testCase), count($ranCommands)); |
||||||
|
|
||||||
|
// Check Generated Commands |
||||||
|
foreach ($testCase as $index => $command) { |
||||||
|
$this->assertEquals($command, $ranCommands[$index]); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
public function testRemoveBadOptionsTask() |
||||||
|
{ |
||||||
|
$runtime = new RuntimeMockup(); |
||||||
|
$runtime->setConfiguration(['environments' => ['test' => []]]); |
||||||
|
$runtime->setEnvironment('test'); |
||||||
|
|
||||||
|
$task = new RemoveTask(); |
||||||
|
$task->setOptions(['from' => 'a.txt']); |
||||||
|
$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 ErrorException); |
||||||
|
$this->assertEquals('Parameter "file" is not defined', $exception->getMessage()); |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -1,364 +0,0 @@ |
|||||||
<?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\BuiltIn; |
|
||||||
|
|
||||||
use Mage\Task\Exception\ErrorException; |
|
||||||
use Mage\Task\BuiltIn\FS\CopyTask; |
|
||||||
use Mage\Task\BuiltIn\FS\LinkTask; |
|
||||||
use Mage\Task\BuiltIn\FS\MoveTask; |
|
||||||
use Mage\Task\BuiltIn\FS\RemoveTask; |
|
||||||
use Exception; |
|
||||||
use Mage\Tests\Runtime\RuntimeMockup; |
|
||||||
use PHPUnit_Framework_TestCase as TestCase; |
|
||||||
|
|
||||||
class FileSystemTaskTest extends TestCase |
|
||||||
{ |
|
||||||
public function testCopyTask() |
|
||||||
{ |
|
||||||
$runtime = new RuntimeMockup(); |
|
||||||
$runtime->setConfiguration(['environments' => ['test' => []]]); |
|
||||||
$runtime->setEnvironment('test'); |
|
||||||
|
|
||||||
$task = new CopyTask(); |
|
||||||
$task->setOptions(['from' => 'a.txt', 'to' => 'b.txt']); |
|
||||||
$task->setRuntime($runtime); |
|
||||||
|
|
||||||
$this->assertContains('a.txt', $task->getDescription()); |
|
||||||
$this->assertContains('b.txt', $task->getDescription()); |
|
||||||
$task->execute(); |
|
||||||
|
|
||||||
$ranCommands = $runtime->getRanCommands(); |
|
||||||
|
|
||||||
$testCase = array( |
|
||||||
0 => 'cp -p a.txt b.txt', |
|
||||||
); |
|
||||||
|
|
||||||
// Check total of Executed Commands |
|
||||||
$this->assertEquals(count($testCase), count($ranCommands)); |
|
||||||
|
|
||||||
// Check Generated Commands |
|
||||||
foreach ($testCase as $index => $command) { |
|
||||||
$this->assertEquals($command, $ranCommands[$index]); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public function testCopyReplaceTask() |
|
||||||
{ |
|
||||||
$runtime = new RuntimeMockup(); |
|
||||||
$runtime->setConfiguration(['environments' => ['test' => []]]); |
|
||||||
$runtime->setEnvironment('test'); |
|
||||||
|
|
||||||
$task = new CopyTask(); |
|
||||||
$task->setOptions(['from' => '%environment%.txt', 'to' => 'b.txt']); |
|
||||||
$task->setRuntime($runtime); |
|
||||||
|
|
||||||
$this->assertContains('test.txt', $task->getDescription()); |
|
||||||
$this->assertContains('b.txt', $task->getDescription()); |
|
||||||
$task->execute(); |
|
||||||
|
|
||||||
$ranCommands = $runtime->getRanCommands(); |
|
||||||
|
|
||||||
$testCase = array( |
|
||||||
0 => 'cp -p test.txt b.txt', |
|
||||||
); |
|
||||||
|
|
||||||
// Check total of Executed Commands |
|
||||||
$this->assertEquals(count($testCase), count($ranCommands)); |
|
||||||
|
|
||||||
// Check Generated Commands |
|
||||||
foreach ($testCase as $index => $command) { |
|
||||||
$this->assertEquals($command, $ranCommands[$index]); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public function testCopyMultipleReplaceTask() |
|
||||||
{ |
|
||||||
$runtime = new RuntimeMockup(); |
|
||||||
$runtime->setConfiguration(['environments' => ['test' => []]]); |
|
||||||
$runtime->setEnvironment('test'); |
|
||||||
$runtime->setReleaseId('1234'); |
|
||||||
$runtime->setWorkingHost('localhost'); |
|
||||||
|
|
||||||
$task = new CopyTask(); |
|
||||||
$task->setOptions(['from' => '%host%.txt', 'to' => '%release%.yml']); |
|
||||||
$task->setRuntime($runtime); |
|
||||||
|
|
||||||
$this->assertContains('localhost.txt', $task->getDescription()); |
|
||||||
$this->assertContains('1234.yml', $task->getDescription()); |
|
||||||
$task->execute(); |
|
||||||
|
|
||||||
$ranCommands = $runtime->getRanCommands(); |
|
||||||
|
|
||||||
$testCase = array( |
|
||||||
0 => 'cp -p localhost.txt 1234.yml', |
|
||||||
); |
|
||||||
|
|
||||||
// Check total of Executed Commands |
|
||||||
$this->assertEquals(count($testCase), count($ranCommands)); |
|
||||||
|
|
||||||
// Check Generated Commands |
|
||||||
foreach ($testCase as $index => $command) { |
|
||||||
$this->assertEquals($command, $ranCommands[$index]); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public function testCopyBadOptionsTask() |
|
||||||
{ |
|
||||||
$runtime = new RuntimeMockup(); |
|
||||||
$runtime->setConfiguration(['environments' => ['test' => []]]); |
|
||||||
$runtime->setEnvironment('test'); |
|
||||||
|
|
||||||
$task = new CopyTask(); |
|
||||||
$task->setOptions(['form' => 'a.txt', 'to' => 'b.txt']); |
|
||||||
$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 ErrorException); |
|
||||||
$this->assertEquals('Parameter "from" is not defined', $exception->getMessage()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public function testMoveTask() |
|
||||||
{ |
|
||||||
$runtime = new RuntimeMockup(); |
|
||||||
$runtime->setConfiguration(['environments' => ['test' => []]]); |
|
||||||
$runtime->setEnvironment('test'); |
|
||||||
|
|
||||||
$task = new MoveTask(); |
|
||||||
$task->setOptions(['from' => 'a.txt', 'to' => 'b.txt']); |
|
||||||
$task->setRuntime($runtime); |
|
||||||
|
|
||||||
$this->assertContains('a.txt', $task->getDescription()); |
|
||||||
$this->assertContains('b.txt', $task->getDescription()); |
|
||||||
$task->execute(); |
|
||||||
|
|
||||||
$ranCommands = $runtime->getRanCommands(); |
|
||||||
|
|
||||||
$testCase = array( |
|
||||||
0 => 'mv a.txt b.txt', |
|
||||||
); |
|
||||||
|
|
||||||
// Check total of Executed Commands |
|
||||||
$this->assertEquals(count($testCase), count($ranCommands)); |
|
||||||
|
|
||||||
// Check Generated Commands |
|
||||||
foreach ($testCase as $index => $command) { |
|
||||||
$this->assertEquals($command, $ranCommands[$index]); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public function testMoveReplaceTask() |
|
||||||
{ |
|
||||||
$runtime = new RuntimeMockup(); |
|
||||||
$runtime->setConfiguration(['environments' => ['test' => []]]); |
|
||||||
$runtime->setEnvironment('test'); |
|
||||||
|
|
||||||
$task = new MoveTask(); |
|
||||||
$task->setOptions(['from' => '%environment%.txt', 'to' => 'b.txt']); |
|
||||||
$task->setRuntime($runtime); |
|
||||||
|
|
||||||
$this->assertContains('test.txt', $task->getDescription()); |
|
||||||
$this->assertContains('b.txt', $task->getDescription()); |
|
||||||
$task->execute(); |
|
||||||
|
|
||||||
$ranCommands = $runtime->getRanCommands(); |
|
||||||
|
|
||||||
$testCase = array( |
|
||||||
0 => 'mv test.txt b.txt', |
|
||||||
); |
|
||||||
|
|
||||||
// Check total of Executed Commands |
|
||||||
$this->assertEquals(count($testCase), count($ranCommands)); |
|
||||||
|
|
||||||
// Check Generated Commands |
|
||||||
foreach ($testCase as $index => $command) { |
|
||||||
$this->assertEquals($command, $ranCommands[$index]); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public function testMoveBadOptionsTask() |
|
||||||
{ |
|
||||||
$runtime = new RuntimeMockup(); |
|
||||||
$runtime->setConfiguration(['environments' => ['test' => []]]); |
|
||||||
$runtime->setEnvironment('test'); |
|
||||||
|
|
||||||
$task = new MoveTask(); |
|
||||||
$task->setOptions(['form' => 'a.txt', 'to' => 'b.txt']); |
|
||||||
$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 ErrorException); |
|
||||||
$this->assertEquals('Parameter "from" is not defined', $exception->getMessage()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public function testRemoveTask() |
|
||||||
{ |
|
||||||
$runtime = new RuntimeMockup(); |
|
||||||
$runtime->setConfiguration(['environments' => ['test' => []]]); |
|
||||||
$runtime->setEnvironment('test'); |
|
||||||
|
|
||||||
$task = new RemoveTask(); |
|
||||||
$task->setOptions(['file' => 'a.txt']); |
|
||||||
$task->setRuntime($runtime); |
|
||||||
|
|
||||||
$this->assertContains('a.txt', $task->getDescription()); |
|
||||||
$task->execute(); |
|
||||||
|
|
||||||
$ranCommands = $runtime->getRanCommands(); |
|
||||||
|
|
||||||
$testCase = array( |
|
||||||
0 => 'rm a.txt', |
|
||||||
); |
|
||||||
|
|
||||||
// Check total of Executed Commands |
|
||||||
$this->assertEquals(count($testCase), count($ranCommands)); |
|
||||||
|
|
||||||
// Check Generated Commands |
|
||||||
foreach ($testCase as $index => $command) { |
|
||||||
$this->assertEquals($command, $ranCommands[$index]); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public function testRemoveReplaceTask() |
|
||||||
{ |
|
||||||
$runtime = new RuntimeMockup(); |
|
||||||
$runtime->setConfiguration(['environments' => ['test' => []]]); |
|
||||||
$runtime->setEnvironment('test'); |
|
||||||
|
|
||||||
$task = new RemoveTask(); |
|
||||||
$task->setOptions(['file' => '%environment%.txt']); |
|
||||||
$task->setRuntime($runtime); |
|
||||||
|
|
||||||
$this->assertContains('test.txt', $task->getDescription()); |
|
||||||
$task->execute(); |
|
||||||
|
|
||||||
$ranCommands = $runtime->getRanCommands(); |
|
||||||
|
|
||||||
$testCase = array( |
|
||||||
0 => 'rm test.txt', |
|
||||||
); |
|
||||||
|
|
||||||
// Check total of Executed Commands |
|
||||||
$this->assertEquals(count($testCase), count($ranCommands)); |
|
||||||
|
|
||||||
// Check Generated Commands |
|
||||||
foreach ($testCase as $index => $command) { |
|
||||||
$this->assertEquals($command, $ranCommands[$index]); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public function testRemoveBadOptionsTask() |
|
||||||
{ |
|
||||||
$runtime = new RuntimeMockup(); |
|
||||||
$runtime->setConfiguration(['environments' => ['test' => []]]); |
|
||||||
$runtime->setEnvironment('test'); |
|
||||||
|
|
||||||
$task = new RemoveTask(); |
|
||||||
$task->setOptions(['from' => 'a.txt']); |
|
||||||
$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 ErrorException); |
|
||||||
$this->assertEquals('Parameter "file" is not defined', $exception->getMessage()); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public function testLinkTask() |
|
||||||
{ |
|
||||||
$runtime = new RuntimeMockup(); |
|
||||||
$runtime->setConfiguration(['environments' => ['test' => []]]); |
|
||||||
$runtime->setEnvironment('test'); |
|
||||||
|
|
||||||
$task = new LinkTask(); |
|
||||||
$task->setOptions(['from' => 'a.txt', 'to' => 'b.txt']); |
|
||||||
$task->setRuntime($runtime); |
|
||||||
|
|
||||||
$this->assertContains('a.txt', $task->getDescription()); |
|
||||||
$this->assertContains('b.txt', $task->getDescription()); |
|
||||||
$task->execute(); |
|
||||||
|
|
||||||
$ranCommands = $runtime->getRanCommands(); |
|
||||||
|
|
||||||
$testCase = array( |
|
||||||
0 => 'ln -snf a.txt b.txt', |
|
||||||
); |
|
||||||
|
|
||||||
// Check total of Executed Commands |
|
||||||
$this->assertEquals(count($testCase), count($ranCommands)); |
|
||||||
|
|
||||||
// Check Generated Commands |
|
||||||
foreach ($testCase as $index => $command) { |
|
||||||
$this->assertEquals($command, $ranCommands[$index]); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public function testLinkReplaceTask() |
|
||||||
{ |
|
||||||
$runtime = new RuntimeMockup(); |
|
||||||
$runtime->setConfiguration(['environments' => ['test' => []]]); |
|
||||||
$runtime->setEnvironment('test'); |
|
||||||
|
|
||||||
$task = new LinkTask(); |
|
||||||
$task->setOptions(['from' => '%environment%.txt', 'to' => 'b.txt']); |
|
||||||
$task->setRuntime($runtime); |
|
||||||
|
|
||||||
$this->assertContains('test.txt', $task->getDescription()); |
|
||||||
$this->assertContains('b.txt', $task->getDescription()); |
|
||||||
$task->execute(); |
|
||||||
|
|
||||||
$ranCommands = $runtime->getRanCommands(); |
|
||||||
|
|
||||||
$testCase = array( |
|
||||||
0 => 'ln -snf test.txt b.txt', |
|
||||||
); |
|
||||||
|
|
||||||
// Check total of Executed Commands |
|
||||||
$this->assertEquals(count($testCase), count($ranCommands)); |
|
||||||
|
|
||||||
// Check Generated Commands |
|
||||||
foreach ($testCase as $index => $command) { |
|
||||||
$this->assertEquals($command, $ranCommands[$index]); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
public function testLinkBadOptionsTask() |
|
||||||
{ |
|
||||||
$runtime = new RuntimeMockup(); |
|
||||||
$runtime->setConfiguration(['environments' => ['test' => []]]); |
|
||||||
$runtime->setEnvironment('test'); |
|
||||||
|
|
||||||
$task = new LinkTask(); |
|
||||||
$task->setOptions(['form' => 'a.txt', 'to' => 'b.txt']); |
|
||||||
$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 ErrorException); |
|
||||||
$this->assertEquals('Parameter "from" is not defined', $exception->getMessage()); |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
Loading…
Reference in new issue