Add build in grunt task

This commit is contained in:
Alexander Schneider 2017-05-20 23:03:57 +02:00
parent 280f48cd18
commit c74f5b6aa7
2 changed files with 89 additions and 0 deletions

View file

@ -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\Task\BuiltIn\Grunt;
use Symfony\Component\Process\Process;
use Mage\Task\AbstractTask;
/**
* Grunt Task - Runs grunt
*
* @author Benjamin Gutmann <benjamin.gutmann@bestit-online.de>
* @author Alexander Schneider <alexanderschneider85@gmail.com>
*/
class RunTask extends AbstractTask
{
public function getName()
{
return 'grunt/run';
}
public function getDescription()
{
return '[Grunt] Run';
}
public function execute()
{
$flags = isset($this->options['flags']) ? $this->options['flags'] : '';
$cmd = sprintf('grunt %s', $flags);
/** @var Process $process */
$process = $this->runtime->runCommand($cmd);
return $process->isSuccessful();
}
}

View file

@ -0,0 +1,45 @@
<?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\Grunt;
use Mage\Task\BuiltIn\Grunt\RunTask;
use Mage\Tests\Runtime\RuntimeMockup;
use PHPUnit_Framework_TestCase as TestCase;
class RunTaskTest extends TestCase
{
public function testRunTask()
{
$runtime = new RuntimeMockup();
$runtime->setConfiguration(['environments' => ['test' => []]]);
$runtime->setEnvironment('test');
$task = new RunTask();
$task->setOptions(['flags' => '--flags']);
$task->setRuntime($runtime);
$this->assertEquals('[Grunt] Run', $task->getDescription());
$task->execute();
$ranCommands = $runtime->getRanCommands();
$testCase = array(
0 => 'grunt --flags',
);
// Check total of Executed Commands
$this->assertEquals(count($testCase), count($ranCommands));
// Check Generated Commands
foreach ($testCase as $index => $command) {
$this->assertEquals($command, $ranCommands[$index]);
}
}
}