mirror of
https://github.com/andres-montanez/Magallanes
synced 2024-05-17 21:26:40 +02:00
Merge pull request #386 from tlode/assetic-dump-timeout
[FEATURE] Add timeout option for assetic:dump task
This commit is contained in:
commit
dbbb35fa70
|
@ -36,7 +36,7 @@ class AsseticDumpTask extends AbstractTask
|
||||||
$command = sprintf('%s assetic:dump --env=%s %s', $options['console'], $options['env'], $options['flags']);
|
$command = sprintf('%s assetic:dump --env=%s %s', $options['console'], $options['env'], $options['flags']);
|
||||||
|
|
||||||
/** @var Process $process */
|
/** @var Process $process */
|
||||||
$process = $this->runtime->runCommand(trim($command));
|
$process = $this->runtime->runCommand(trim($command), $options['timeout']);
|
||||||
|
|
||||||
return $process->isSuccessful();
|
return $process->isSuccessful();
|
||||||
}
|
}
|
||||||
|
@ -44,7 +44,7 @@ class AsseticDumpTask extends AbstractTask
|
||||||
protected function getOptions()
|
protected function getOptions()
|
||||||
{
|
{
|
||||||
$options = array_merge(
|
$options = array_merge(
|
||||||
['console' => 'bin/console', 'env' => 'dev', 'flags' => ''],
|
['console' => 'bin/console', 'env' => 'dev', 'flags' => '', 'timeout' => 120],
|
||||||
$this->runtime->getMergedOption('symfony'),
|
$this->runtime->getMergedOption('symfony'),
|
||||||
$this->options
|
$this->options
|
||||||
);
|
);
|
||||||
|
|
|
@ -16,6 +16,7 @@ use Symfony\Component\Process\Process;
|
||||||
class RuntimeMockup extends Runtime
|
class RuntimeMockup extends Runtime
|
||||||
{
|
{
|
||||||
protected $ranCommands = [];
|
protected $ranCommands = [];
|
||||||
|
protected $ranCommandTimeouts = [];
|
||||||
protected $forceFail = [];
|
protected $forceFail = [];
|
||||||
|
|
||||||
public function getRanCommands()
|
public function getRanCommands()
|
||||||
|
@ -23,6 +24,11 @@ class RuntimeMockup extends Runtime
|
||||||
return $this->ranCommands;
|
return $this->ranCommands;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getRanCommandTimeoutFor($cmd)
|
||||||
|
{
|
||||||
|
return isset($this->ranCommandTimeouts[$cmd]) ? $this->ranCommandTimeouts[$cmd] : null;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generate the Release ID
|
* Generate the Release ID
|
||||||
*
|
*
|
||||||
|
@ -44,6 +50,7 @@ class RuntimeMockup extends Runtime
|
||||||
public function runLocalCommand($cmd, $timeout = 120)
|
public function runLocalCommand($cmd, $timeout = 120)
|
||||||
{
|
{
|
||||||
$this->ranCommands[] = $cmd;
|
$this->ranCommands[] = $cmd;
|
||||||
|
$this->ranCommandTimeouts[$cmd] = $timeout;
|
||||||
|
|
||||||
$process = new ProcessMockup($cmd);
|
$process = new ProcessMockup($cmd);
|
||||||
$process->forceFail = $this->forceFail;
|
$process->forceFail = $this->forceFail;
|
||||||
|
|
70
tests/Task/BuiltIn/Symfony/AsseticDumpTaskTest.php
Normal file
70
tests/Task/BuiltIn/Symfony/AsseticDumpTaskTest.php
Normal file
|
@ -0,0 +1,70 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Mage\tests\Task\BuiltIn\Symfony;
|
||||||
|
|
||||||
|
|
||||||
|
use Mage\Task\BuiltIn\Symfony\AsseticDumpTask;
|
||||||
|
use Mage\Tests\Runtime\RuntimeMockup;
|
||||||
|
|
||||||
|
class AsseticDumpTaskTest extends \PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @var RuntimeMockup
|
||||||
|
*/
|
||||||
|
private $runtime;
|
||||||
|
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->runtime = new RuntimeMockup();
|
||||||
|
$this->runtime->setConfiguration(['environments' => ['test' => []]]);
|
||||||
|
$this->runtime->setEnvironment('test');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAsseticDumpTask()
|
||||||
|
{
|
||||||
|
$task = new AsseticDumpTask();
|
||||||
|
$task->setOptions(['env' => 'test']);
|
||||||
|
$task->setRuntime($this->runtime);
|
||||||
|
$this->assertEquals('[Symfony] Assetic Dump', $task->getDescription());
|
||||||
|
$task->execute();
|
||||||
|
|
||||||
|
$testCase = [
|
||||||
|
'bin/console assetic:dump --env=test' => 120,
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->assertRanCommands($testCase);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAsseticDumpTaskWithTimeoutOption()
|
||||||
|
{
|
||||||
|
$task = new AsseticDumpTask();
|
||||||
|
$task->setOptions(['env' => 'test', 'timeout' => 300]);
|
||||||
|
$task->setRuntime($this->runtime);
|
||||||
|
$task->execute();
|
||||||
|
|
||||||
|
|
||||||
|
$testCase = [
|
||||||
|
'bin/console assetic:dump --env=test' => 300,
|
||||||
|
];
|
||||||
|
|
||||||
|
$this->assertRanCommands($testCase);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $testCase
|
||||||
|
*/
|
||||||
|
private function assertRanCommands($testCase)
|
||||||
|
{
|
||||||
|
$ranCommands = $this->runtime->getRanCommands();
|
||||||
|
|
||||||
|
// Check total of Executed Commands
|
||||||
|
$this->assertEquals(count($testCase), count($ranCommands));
|
||||||
|
|
||||||
|
// Check Generated Commands
|
||||||
|
$index = 0;
|
||||||
|
foreach ($testCase as $command => $timeout) {
|
||||||
|
$this->assertEquals($command, $ranCommands[$index++]);
|
||||||
|
$this->assertEquals($timeout, $this->runtime->getRanCommandTimeoutFor($command));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue