Skip to content

Commit

Permalink
Automatically add event description when scheduling a command (#40286)
Browse files Browse the repository at this point in the history
  • Loading branch information
Maarten Paauw authored Jan 7, 2022
1 parent bed54df commit 0fb801a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Illuminate/Console/Scheduling/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,11 @@ public function call($callback, array $parameters = [])
public function command($command, array $parameters = [])
{
if (class_exists($command)) {
$command = Container::getInstance()->make($command)->getName();
$command = Container::getInstance()->make($command);

return $this->exec(
Application::formatCommandString($command->getName()), $parameters,
)->description($command->getDescription());
}

return $this->exec(
Expand Down
17 changes: 17 additions & 0 deletions tests/Console/ConsoleEventSchedulerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,21 @@ public function testCreateNewArtisanCommandUsingCommandClass()
$this->assertEquals($binary.' '.$artisan.' foo:bar --force', $events[0]->command);
}

public function testItUsesCommandDescriptionAsEventDescription()
{
$schedule = $this->schedule;
$event = $schedule->command(ConsoleCommandStub::class);
$this->assertEquals('This is a description about the command', $event->description);
}

public function testItShouldBePossibleToOverwriteTheDescription()
{
$schedule = $this->schedule;
$event = $schedule->command(ConsoleCommandStub::class)
->description('This is an alternative description');
$this->assertEquals('This is an alternative description', $event->description);
}

public function testCallCreatesNewJobWithTimezone()
{
$schedule = new Schedule('UTC');
Expand Down Expand Up @@ -148,6 +163,8 @@ class ConsoleCommandStub extends Command
{
protected $signature = 'foo:bar';

protected $description = 'This is a description about the command';

protected $foo;

public function __construct(FooClassStub $foo)
Expand Down

0 comments on commit 0fb801a

Please sign in to comment.