diff --git a/src/Scripts/ScriptRunner.php b/src/Scripts/ScriptRunner.php index 0a12e316..588e0ad3 100644 --- a/src/Scripts/ScriptRunner.php +++ b/src/Scripts/ScriptRunner.php @@ -63,8 +63,11 @@ public function setWorkingDir($workingDir) public function run($scriptName) { foreach ($this->scripts as $scripts) { - if (isset($scripts[$scriptName]) && !empty($scripts[$scriptName])) { + if (!empty($scripts[$scriptName])) { + $this->io->text(sprintf('Running scripts for "%s"', $scriptName)); + $this->io->progressStart(count($scripts[$scriptName])); $this->runScripts($scriptName, $scripts); + $this->io->progressFinish(); } } } @@ -78,16 +81,14 @@ public function run($scriptName) */ private function runScripts($scriptName, $scripts) { - $this->io->text(sprintf('Running scripts for "%s"', $scriptName)); - foreach ($scripts[$scriptName] as $script) { if (strpos($script, '@') === 0) { // NB: Infinite recursion detection happens when processing the config $script = substr($script, 1); $this->runScripts($script, $scripts); } else { - $this->io->text(sprintf('$ "%s" in "%s"', $script, $this->getWorkingDir())); $this->processRunner->run($script, $this->getWorkingDir()); + $this->io->progressAdvance(); } } $this->io->newLine(); diff --git a/tests/Scripts/ScriptRunnerTest.php b/tests/Scripts/ScriptRunnerTest.php index e8225e5f..61936770 100644 --- a/tests/Scripts/ScriptRunnerTest.php +++ b/tests/Scripts/ScriptRunnerTest.php @@ -171,4 +171,37 @@ public function testRunsCombinedReferencedScriptWithMultipleCommands() $scriptRunner->run('test'); } + + public function testRunUpdatesProgressBar() + { + $mockIO = Mockery::mock(\Meteor\IO\IOInterface::class, [ + 'text' => null, + 'debug' => null, + 'newLine' => null, + ]); + + $mockIO->shouldReceive('progressStart') + ->once() + ->with(2); + + $mockIO->shouldReceive('progressAdvance') + ->twice(); + + $mockIO->shouldReceive('progressFinish') + ->once(); + + $this->processRunner->shouldReceive('run') + ->withAnyArgs() + ->twice(); + + $scriptRunner = new ScriptRunner($this->processRunner, $mockIO, [ + 'jadu/cms' => [ + 'test' => ['@clear-cache', '@warm-cache'], + 'clear-cache' => ['clear-cache.sh'], + 'warm-cache' => ['warm-cache.sh'], + ], + ]); + + $scriptRunner->run('test'); + } }