Skip to content

Commit 0fb801a

Browse files
author
Maarten Paauw
authored
Automatically add event description when scheduling a command (#40286)
1 parent bed54df commit 0fb801a

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/Illuminate/Console/Scheduling/Schedule.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,11 @@ public function call($callback, array $parameters = [])
120120
public function command($command, array $parameters = [])
121121
{
122122
if (class_exists($command)) {
123-
$command = Container::getInstance()->make($command)->getName();
123+
$command = Container::getInstance()->make($command);
124+
125+
return $this->exec(
126+
Application::formatCommandString($command->getName()), $parameters,
127+
)->description($command->getDescription());
124128
}
125129

126130
return $this->exec(

tests/Console/ConsoleEventSchedulerTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,21 @@ public function testCreateNewArtisanCommandUsingCommandClass()
120120
$this->assertEquals($binary.' '.$artisan.' foo:bar --force', $events[0]->command);
121121
}
122122

123+
public function testItUsesCommandDescriptionAsEventDescription()
124+
{
125+
$schedule = $this->schedule;
126+
$event = $schedule->command(ConsoleCommandStub::class);
127+
$this->assertEquals('This is a description about the command', $event->description);
128+
}
129+
130+
public function testItShouldBePossibleToOverwriteTheDescription()
131+
{
132+
$schedule = $this->schedule;
133+
$event = $schedule->command(ConsoleCommandStub::class)
134+
->description('This is an alternative description');
135+
$this->assertEquals('This is an alternative description', $event->description);
136+
}
137+
123138
public function testCallCreatesNewJobWithTimezone()
124139
{
125140
$schedule = new Schedule('UTC');
@@ -148,6 +163,8 @@ class ConsoleCommandStub extends Command
148163
{
149164
protected $signature = 'foo:bar';
150165

166+
protected $description = 'This is a description about the command';
167+
151168
protected $foo;
152169

153170
public function __construct(FooClassStub $foo)

0 commit comments

Comments
 (0)