Skip to content

Commit

Permalink
[10.x] Add displayName for queued Artisan commands (#48778)
Browse files Browse the repository at this point in the history
* Add `displayName` for queued Artisan commands

* Match handle method
  • Loading branch information
jessarcher authored Oct 20, 2023
1 parent cee91ab commit 61ea0bc
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Illuminate/Foundation/Console/QueuedCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,14 @@ public function handle(KernelContract $kernel)
{
$kernel->call(...array_values($this->data));
}

/**
* Get the display name for the queued job.
*
* @return string
*/
public function displayName()
{
return array_values($this->data)[0];
}
}
15 changes: 15 additions & 0 deletions tests/Integration/Console/ConsoleApplicationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
use Illuminate\Console\Command;
use Illuminate\Console\Scheduling\Schedule;
use Illuminate\Contracts\Console\Kernel;
use Illuminate\Foundation\Console\QueuedCommand;
use Illuminate\Support\Facades\Queue;
use Orchestra\Testbench\TestCase;

class ConsoleApplicationTest extends TestCase
Expand Down Expand Up @@ -65,6 +67,19 @@ public function testArtisanInstantiateScheduleWhenNeed()

$this->assertTrue($this->app->resolved(Schedule::class));
}

public function testArtisanQueue()
{
Queue::fake();

$this->app[Kernel::class]->queue('foo:bar', [
'id' => 1,
]);

Queue::assertPushed(QueuedCommand::class, function ($job) {
return $job->displayName() === 'foo:bar';
});
}
}

class FooCommandStub extends Command
Expand Down

0 comments on commit 61ea0bc

Please sign in to comment.