Skip to content

Commit

Permalink
[minor][SMALL BC BREAK] schedule:run now has no output for no tasks (#49
Browse files Browse the repository at this point in the history
)

- passing -vvv to schedule:run brings back the old behavior
- closes #48
  • Loading branch information
kbond authored Sep 13, 2021
1 parent 49ade72 commit 7649b18
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 13 deletions.
24 changes: 12 additions & 12 deletions src/EventListener/ScheduleConsoleOutputSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,20 +78,20 @@ public function beforeSchedule(BeforeScheduleEvent $event): void
$allTaskCount = \count($context->getSchedule()->all());
$dueTaskCount = \count($context->dueTasks());

if (0 === $dueTaskCount) {
$this->io->note(\sprintf('No tasks due to run. (%s total tasks)', $allTaskCount));

return;
if ($dueTaskCount > 0) {
$this->io->comment(\sprintf(
'%sRunning <info>%s</info> %stask%s. (%s total tasks)',
$context->isForceRun() ? '<error>Force</error> ' : '',
$dueTaskCount,
$context->isForceRun() ? '' : 'due ',
$dueTaskCount > 1 ? 's' : '',
$allTaskCount
));
}

$this->io->comment(\sprintf(
'%sRunning <info>%s</info> %stask%s. (%s total tasks)',
$context->isForceRun() ? '<error>Force</error> ' : '',
$dueTaskCount,
$context->isForceRun() ? '' : 'due ',
$dueTaskCount > 1 ? 's' : '',
$allTaskCount
));
if ($this->io->isDebug()) {
$this->io->note(\sprintf('No tasks due to run. (%s total tasks)', $allTaskCount));
}
}

public function beforeTask(BeforeTaskEvent $event): void
Expand Down
17 changes: 16 additions & 1 deletion tests/Command/ScheduleRunCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,29 @@ final class ScheduleRunCommandTest extends TestCase
/**
* @test
*/
public function no_tasks_defined()
public function no_tasks_defined(): void
{
$dispatcher = new EventDispatcher();
$runner = (new MockScheduleBuilder())->getRunner($dispatcher);
$commandTester = new CommandTester(new ScheduleRunCommand($runner, $dispatcher));

$exit = $commandTester->execute([]);

$this->assertSame(0, $exit);
$this->assertSame('', $commandTester->getDisplay());
}

/**
* @test
*/
public function no_tasks_defined_debug()
{
$dispatcher = new EventDispatcher();
$runner = (new MockScheduleBuilder())->getRunner($dispatcher);
$commandTester = new CommandTester(new ScheduleRunCommand($runner, $dispatcher));

$exit = $commandTester->execute([], ['verbosity' => OutputInterface::VERBOSITY_DEBUG]);

$this->assertSame(0, $exit);
$this->assertStringContainsString('No tasks due to run. (0 total tasks)', $commandTester->getDisplay());
}
Expand Down

0 comments on commit 7649b18

Please sign in to comment.