Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/Scripts/ScriptRunner.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand All @@ -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();
Expand Down
33 changes: 33 additions & 0 deletions tests/Scripts/ScriptRunnerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}