mirror of https://github.com/hauke68/Magallanes
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
128 lines
3.9 KiB
128 lines
3.9 KiB
8 years ago
|
<?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.
|
||
|
*/
|
||
|
|
||
8 years ago
|
namespace Mage\Tests\Task\BuiltIn\FileSystem;
|
||
8 years ago
|
|
||
|
use Mage\Task\Exception\ErrorException;
|
||
8 years ago
|
use Mage\Task\BuiltIn\FS\LinkTask;
|
||
8 years ago
|
use Exception;
|
||
|
use Mage\Tests\Runtime\RuntimeMockup;
|
||
|
use PHPUnit_Framework_TestCase as TestCase;
|
||
|
|
||
8 years ago
|
class LinkTaskTest extends TestCase
|
||
8 years ago
|
{
|
||
8 years ago
|
public function testLinkTask()
|
||
8 years ago
|
{
|
||
|
$runtime = new RuntimeMockup();
|
||
|
$runtime->setConfiguration(['environments' => ['test' => []]]);
|
||
|
$runtime->setEnvironment('test');
|
||
|
|
||
8 years ago
|
$task = new LinkTask();
|
||
|
$task->setOptions(['from' => 'a.txt', 'to' => 'b.txt']);
|
||
8 years ago
|
$task->setRuntime($runtime);
|
||
|
|
||
|
$this->assertContains('a.txt', $task->getDescription());
|
||
8 years ago
|
$this->assertContains('b.txt', $task->getDescription());
|
||
8 years ago
|
$task->execute();
|
||
|
|
||
|
$ranCommands = $runtime->getRanCommands();
|
||
|
|
||
|
$testCase = array(
|
||
8 years ago
|
0 => 'ln -snf "a.txt" "b.txt"',
|
||
8 years ago
|
);
|
||
|
|
||
|
// Check total of Executed Commands
|
||
|
$this->assertEquals(count($testCase), count($ranCommands));
|
||
8 years ago
|
|
||
|
// Check Generated Commands
|
||
|
foreach ($testCase as $index => $command) {
|
||
|
$this->assertEquals($command, $ranCommands[$index]);
|
||
|
}
|
||
|
}
|
||
|
|
||
8 years ago
|
public function testLinkTaskWithFlags()
|
||
8 years ago
|
{
|
||
|
$runtime = new RuntimeMockup();
|
||
|
$runtime->setConfiguration(['environments' => ['test' => []]]);
|
||
|
$runtime->setEnvironment('test');
|
||
|
|
||
8 years ago
|
$task = new LinkTask();
|
||
|
$task->setOptions(['from' => 'a.txt', 'to' => 'b.txt', 'flags' => '-P']);
|
||
8 years ago
|
$task->setRuntime($runtime);
|
||
|
|
||
|
$this->assertContains('a.txt', $task->getDescription());
|
||
8 years ago
|
$this->assertContains('b.txt', $task->getDescription());
|
||
8 years ago
|
$task->execute();
|
||
|
|
||
|
$ranCommands = $runtime->getRanCommands();
|
||
|
|
||
|
$testCase = array(
|
||
8 years ago
|
0 => 'ln -P "a.txt" "b.txt"',
|
||
8 years ago
|
);
|
||
|
|
||
|
// Check total of Executed Commands
|
||
|
$this->assertEquals(count($testCase), count($ranCommands));
|
||
8 years ago
|
|
||
|
// Check Generated Commands
|
||
|
foreach ($testCase as $index => $command) {
|
||
|
$this->assertEquals($command, $ranCommands[$index]);
|
||
|
}
|
||
|
}
|
||
|
|
||
8 years ago
|
public function testLinkReplaceTask()
|
||
8 years ago
|
{
|
||
|
$runtime = new RuntimeMockup();
|
||
|
$runtime->setConfiguration(['environments' => ['test' => []]]);
|
||
|
$runtime->setEnvironment('test');
|
||
|
|
||
8 years ago
|
$task = new LinkTask();
|
||
|
$task->setOptions(['from' => '%environment%.txt', 'to' => 'b.txt']);
|
||
8 years ago
|
$task->setRuntime($runtime);
|
||
|
|
||
|
$this->assertContains('test.txt', $task->getDescription());
|
||
8 years ago
|
$this->assertContains('b.txt', $task->getDescription());
|
||
8 years ago
|
$task->execute();
|
||
|
|
||
|
$ranCommands = $runtime->getRanCommands();
|
||
|
|
||
|
$testCase = array(
|
||
8 years ago
|
0 => 'ln -snf "test.txt" "b.txt"',
|
||
8 years ago
|
);
|
||
|
|
||
|
// Check total of Executed Commands
|
||
|
$this->assertEquals(count($testCase), count($ranCommands));
|
||
|
|
||
|
// Check Generated Commands
|
||
|
foreach ($testCase as $index => $command) {
|
||
|
$this->assertEquals($command, $ranCommands[$index]);
|
||
|
}
|
||
|
}
|
||
|
|
||
8 years ago
|
public function testLinkBadOptionsTask()
|
||
8 years ago
|
{
|
||
|
$runtime = new RuntimeMockup();
|
||
|
$runtime->setConfiguration(['environments' => ['test' => []]]);
|
||
|
$runtime->setEnvironment('test');
|
||
|
|
||
8 years ago
|
$task = new LinkTask();
|
||
|
$task->setOptions(['form' => 'a.txt', 'to' => 'b.txt']);
|
||
8 years ago
|
$task->setRuntime($runtime);
|
||
|
|
||
|
try {
|
||
|
$this->assertContains('[missing parameters]', $task->getDescription());
|
||
|
$task->execute();
|
||
8 years ago
|
$this->assertTrue(false, 'Task did not failed');
|
||
8 years ago
|
} catch (Exception $exception) {
|
||
|
$this->assertTrue($exception instanceof ErrorException);
|
||
8 years ago
|
$this->assertEquals('Parameter "from" is not defined', $exception->getMessage());
|
||
8 years ago
|
}
|
||
|
}
|
||
|
}
|