From 21bcdf76cc9e20223586bf6bffc48cb5e6b7d9c3 Mon Sep 17 00:00:00 2001 From: Tobias Lode Date: Mon, 29 May 2017 10:07:13 +0200 Subject: [PATCH 1/2] Add timeout option for assetic:dump task --- src/Task/BuiltIn/Symfony/AsseticDumpTask.php | 4 +- tests/Runtime/RuntimeMockup.php | 7 ++ .../BuiltIn/Symfony/AsseticDumpTaskTest.php | 70 +++++++++++++++++++ 3 files changed, 79 insertions(+), 2 deletions(-) create mode 100644 tests/Task/BuiltIn/Symfony/AsseticDumpTaskTest.php diff --git a/src/Task/BuiltIn/Symfony/AsseticDumpTask.php b/src/Task/BuiltIn/Symfony/AsseticDumpTask.php index 3f23d19..8d1400c 100644 --- a/src/Task/BuiltIn/Symfony/AsseticDumpTask.php +++ b/src/Task/BuiltIn/Symfony/AsseticDumpTask.php @@ -36,7 +36,7 @@ class AsseticDumpTask extends AbstractTask $command = sprintf('%s assetic:dump --env=%s %s', $options['console'], $options['env'], $options['flags']); /** @var Process $process */ - $process = $this->runtime->runCommand(trim($command)); + $process = $this->runtime->runCommand(trim($command), $options['timeout']); return $process->isSuccessful(); } @@ -44,7 +44,7 @@ class AsseticDumpTask extends AbstractTask protected function getOptions() { $options = array_merge( - ['console' => 'bin/console', 'env' => 'dev', 'flags' => ''], + ['console' => 'bin/console', 'env' => 'dev', 'flags' => '', 'timeout' => 120], $this->runtime->getMergedOption('symfony'), $this->options ); diff --git a/tests/Runtime/RuntimeMockup.php b/tests/Runtime/RuntimeMockup.php index 622da0c..e5377b4 100644 --- a/tests/Runtime/RuntimeMockup.php +++ b/tests/Runtime/RuntimeMockup.php @@ -16,6 +16,7 @@ use Symfony\Component\Process\Process; class RuntimeMockup extends Runtime { protected $ranCommands = []; + protected $ranCommandTimeouts = []; protected $forceFail = []; public function getRanCommands() @@ -23,6 +24,11 @@ class RuntimeMockup extends Runtime return $this->ranCommands; } + public function getRanCommandTimeoutFor($cmd) + { + return $this->ranCommandTimeouts[$cmd] ?? null; + } + /** * Generate the Release ID * @@ -44,6 +50,7 @@ class RuntimeMockup extends Runtime public function runLocalCommand($cmd, $timeout = 120) { $this->ranCommands[] = $cmd; + $this->ranCommandTimeouts[$cmd] = $timeout; $process = new ProcessMockup($cmd); $process->forceFail = $this->forceFail; diff --git a/tests/Task/BuiltIn/Symfony/AsseticDumpTaskTest.php b/tests/Task/BuiltIn/Symfony/AsseticDumpTaskTest.php new file mode 100644 index 0000000..b481f47 --- /dev/null +++ b/tests/Task/BuiltIn/Symfony/AsseticDumpTaskTest.php @@ -0,0 +1,70 @@ +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)); + } + } +} From 66191b7088e7748930ad6f83f933cd89add0aa11 Mon Sep 17 00:00:00 2001 From: Tobias Lode Date: Mon, 29 May 2017 10:38:58 +0200 Subject: [PATCH 2/2] Remove coalesce operator Remove strict types declaration --- tests/Runtime/RuntimeMockup.php | 2 +- tests/Task/BuiltIn/Symfony/AsseticDumpTaskTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/Runtime/RuntimeMockup.php b/tests/Runtime/RuntimeMockup.php index e5377b4..65b6c32 100644 --- a/tests/Runtime/RuntimeMockup.php +++ b/tests/Runtime/RuntimeMockup.php @@ -26,7 +26,7 @@ class RuntimeMockup extends Runtime public function getRanCommandTimeoutFor($cmd) { - return $this->ranCommandTimeouts[$cmd] ?? null; + return isset($this->ranCommandTimeouts[$cmd]) ? $this->ranCommandTimeouts[$cmd] : null; } /** diff --git a/tests/Task/BuiltIn/Symfony/AsseticDumpTaskTest.php b/tests/Task/BuiltIn/Symfony/AsseticDumpTaskTest.php index b481f47..e1f694e 100644 --- a/tests/Task/BuiltIn/Symfony/AsseticDumpTaskTest.php +++ b/tests/Task/BuiltIn/Symfony/AsseticDumpTaskTest.php @@ -1,4 +1,4 @@ -