From 56f97690a44bb3c509a5d58a0d2f6f396f618fc4 Mon Sep 17 00:00:00 2001 From: Robert Boes <2871897+RobertBoes@users.noreply.github.com> Date: Fri, 12 Apr 2024 13:48:10 +0200 Subject: [PATCH] =?UTF-8?q?Revert=20"[11.x]=20Name=20of=20job=20set=20by?= =?UTF-8?q?=20displayName()=20must=20be=20honoured=20by=20Schedule=20?= =?UTF-8?q?=E2=80=A6"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit d63d2b1f50b6bbf8beb88b7b4ad5a4d230244443. --- .../Console/Scheduling/Schedule.php | 22 +++---- .../Fixtures/JobToTestWithSchedule.php | 14 ----- tests/Console/Scheduling/ScheduleTest.php | 62 ------------------- 3 files changed, 9 insertions(+), 89 deletions(-) delete mode 100644 tests/Console/Fixtures/JobToTestWithSchedule.php delete mode 100644 tests/Console/Scheduling/ScheduleTest.php 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'], - ]; - } -}