diff --git a/src/Illuminate/Console/Scheduling/Schedule.php b/src/Illuminate/Console/Scheduling/Schedule.php index 65292e2fc16e..684aec58fc4a 100644 --- a/src/Illuminate/Console/Scheduling/Schedule.php +++ b/src/Illuminate/Console/Scheduling/Schedule.php @@ -154,19 +154,15 @@ public function command($command, array $parameters = []) */ public function job($job, $queue = null, $connection = null) { - $instance = is_string($job) - ? Container::getInstance()->make($job) - : $job; - - $name = method_exists($instance, 'displayName') - ? $instance->displayName() - : $instance::class; - - return $this->call(function () use ($instance, $queue, $connection) { - $instance instanceof ShouldQueue - ? $this->dispatchToQueue($instance, $queue ?? $instance->queue, $connection ?? $instance->connection) - : $this->dispatchNow($instance); - })->name($name); + return $this->call(function () use ($job, $queue, $connection) { + $job = is_string($job) ? Container::getInstance()->make($job) : $job; + + if ($job instanceof ShouldQueue) { + $this->dispatchToQueue($job, $queue ?? $job->queue, $connection ?? $job->connection); + } else { + $this->dispatchNow($job); + } + })->name(is_string($job) ? $job : get_class($job)); } /** diff --git a/tests/Console/Fixtures/JobToTestWithSchedule.php b/tests/Console/Fixtures/JobToTestWithSchedule.php deleted file mode 100644 index 78924c79131b..000000000000 --- a/tests/Console/Fixtures/JobToTestWithSchedule.php +++ /dev/null @@ -1,14 +0,0 @@ -container = new Container; - Container::setInstance($this->container); - $this->eventMutex = m::mock(EventMutex::class); - $this->container->instance(EventMutex::class, $this->eventMutex); - $this->schedulingMutex = m::mock(SchedulingMutex::class); - $this->container->instance(SchedulingMutex::class, $this->schedulingMutex); - } - - #[DataProvider('jobHonoursDisplayNameIfMethodExistsProvider')] - public function testJobHonoursDisplayNameIfMethodExists(string|object $job, string $jobName): void - { - $schedule = new Schedule(); - $scheduledJob = $schedule->job($job); - self::assertSame($jobName, $scheduledJob->description); - } - - public static function jobHonoursDisplayNameIfMethodExistsProvider(): array - { - $job = new class implements ShouldQueue - { - public function displayName(): string - { - return 'testJob-123'; - } - }; - - return [ - [JobToTestWithSchedule::class, JobToTestWithSchedule::class], - [new JobToTestWithSchedule, JobToTestWithSchedule::class], - [$job, 'testJob-123'], - ]; - } -}