From 71203fc75147341f95feb3d9e4e6a2c18972c082 Mon Sep 17 00:00:00 2001 From: Doug Sisk Date: Wed, 22 Jan 2025 11:56:56 -0500 Subject: [PATCH] [11.x] Fix unique jobs that have a uniqueVia method (#54294) * Adds test for uniqueVia job dispatch * Make getName public --- src/Illuminate/Cache/Repository.php | 2 +- tests/Integration/Queue/UniqueJobTest.php | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Cache/Repository.php b/src/Illuminate/Cache/Repository.php index a01f4aedb209..a5f1df9db137 100755 --- a/src/Illuminate/Cache/Repository.php +++ b/src/Illuminate/Cache/Repository.php @@ -638,7 +638,7 @@ protected function getSeconds($ttl) * * @return string|null */ - protected function getName() + public function getName() { return $this->config['store'] ?? null; } diff --git a/tests/Integration/Queue/UniqueJobTest.php b/tests/Integration/Queue/UniqueJobTest.php index 82e567282a6f..5ec58efdec2b 100644 --- a/tests/Integration/Queue/UniqueJobTest.php +++ b/tests/Integration/Queue/UniqueJobTest.php @@ -4,6 +4,7 @@ use Exception; use Illuminate\Bus\Queueable; +use Illuminate\Container\Container; use Illuminate\Contracts\Cache\Repository as Cache; use Illuminate\Contracts\Queue\ShouldBeUnique; use Illuminate\Contracts\Queue\ShouldBeUniqueUntilProcessing; @@ -51,6 +52,14 @@ public function testUniqueJobsAreNotDispatched() ); } + public function testUniqueJobWithViaDispatched() + { + Bus::fake(); + + UniqueViaJob::dispatch(); + Bus::assertDispatched(UniqueViaJob::class); + } + public function testLockIsReleasedForSuccessfulJobs() { UniqueTestJob::$handled = false; @@ -222,3 +231,11 @@ public function __construct(public User $user) { } } + +class UniqueViaJob extends UniqueTestJob +{ + public function uniqueVia(): Cache + { + return Container::getInstance()->make(Cache::class); + } +}