diff --git a/src/Task/BuiltIn/Grunt/RunTask.php b/src/Task/BuiltIn/Grunt/RunTask.php new file mode 100644 index 0000000..df6c0a5 --- /dev/null +++ b/src/Task/BuiltIn/Grunt/RunTask.php @@ -0,0 +1,44 @@ + + * + * 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 + * @author Alexander Schneider + */ +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(); + } +} diff --git a/tests/Task/BuiltIn/Grunt/RunTaskTest.php b/tests/Task/BuiltIn/Grunt/RunTaskTest.php new file mode 100644 index 0000000..fc00b63 --- /dev/null +++ b/tests/Task/BuiltIn/Grunt/RunTaskTest.php @@ -0,0 +1,45 @@ + + * + * 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]); + } + } +}