Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Option to schedule tasks using the command class instead of it's signature #15591

Merged
merged 3 commits into from
Sep 26, 2016
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
4 changes: 4 additions & 0 deletions src/Illuminate/Console/Scheduling/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ public function call($callback, array $parameters = [])
*/
public function command($command, array $parameters = [])
{
if (class_exists($command)) {
$command = app($command)->getName();
}

$binary = ProcessUtils::escapeArgument((new PhpExecutableFinder)->find(false));

$artisan = defined('ARTISAN_BINARY') ? ProcessUtils::escapeArgument(ARTISAN_BINARY) : 'artisan';
Expand Down
36 changes: 36 additions & 0 deletions tests/Console/ConsoleEventSchedulerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,40 @@ public function testCommandCreatesNewArtisanCommand()
$this->assertEquals($binary.' artisan queue:listen --tries=3', $events[1]->command);
$this->assertEquals($binary.' artisan queue:listen --tries=3', $events[2]->command);
}

public function testCreateNewArtisanCommandUsingCommandClass()
{
$escape = '\\' === DIRECTORY_SEPARATOR ? '"' : '\'';

$schedule = new Schedule;
$schedule->command(ConsoleCommandStub::class, ['--force']);

$events = $schedule->events();
$binary = $escape.PHP_BINARY.$escape;
$this->assertEquals($binary.' artisan foo:bar --force', $events[0]->command);
}
}

class FooClassStub
{
protected $schedule;

public function __construct(Schedule $schedule)
{
$this->schedule = $schedule;
}
}

class ConsoleCommandStub extends Illuminate\Console\Command
{
protected $signature = 'foo:bar';

protected $foo;

public function __construct(FooClassStub $foo)
{
parent::__construct();

$this->foo = $foo;
}
}