diff --git a/src/Task/BuiltIn/Npm/InstallTask.php b/src/Task/BuiltIn/Npm/InstallTask.php new file mode 100644 index 0000000..d447964 --- /dev/null +++ b/src/Task/BuiltIn/Npm/InstallTask.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\Npm; + +use Symfony\Component\Process\Process; +use Mage\Task\AbstractTask; + +/** + * NPM Task - Installs npn packages + * + * @author Benjamin Gutmann + * @author Alexander Schneider + */ +class InstallTask extends AbstractTask +{ + public function getName() + { + return 'npm/install'; + } + + public function getDescription() + { + return '[NPM] Install'; + } + + public function execute() + { + $flags = isset($this->options['flags']) ? $this->options['flags'] : ''; + $cmd = sprintf('npm install %s', $flags); + + /** @var Process $process */ + $process = $this->runtime->runCommand($cmd); + + return $process->isSuccessful(); + } +} diff --git a/tests/Task/BuiltIn/Npm/InstallTaskTest.php b/tests/Task/BuiltIn/Npm/InstallTaskTest.php new file mode 100644 index 0000000..8619395 --- /dev/null +++ b/tests/Task/BuiltIn/Npm/InstallTaskTest.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\Tests\Task\BuiltIn\Npm; + +use Mage\Task\BuiltIn\Npm\InstallTask; +use Mage\Tests\Runtime\RuntimeMockup; +use PHPUnit_Framework_TestCase as TestCase; + +class InstallTaskTest extends TestCase +{ + public function testInstallTask() + { + $runtime = new RuntimeMockup(); + $runtime->setConfiguration(['environments' => ['test' => []]]); + $runtime->setEnvironment('test'); + + $task = new InstallTask(); + $task->setOptions(['flags' => '--flags']); + $task->setRuntime($runtime); + $this->assertEquals('[NPM] Install', $task->getDescription()); + + $task->execute(); + + $ranCommands = $runtime->getRanCommands(); + $testCase = array( + 0 => 'npm install --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]); + } + } +}