Skip to content

Commit 71203fc

Browse files
authored
[11.x] Fix unique jobs that have a uniqueVia method (#54294)
* Adds test for uniqueVia job dispatch * Make getName public
1 parent 1c2a6c1 commit 71203fc

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/Illuminate/Cache/Repository.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ protected function getSeconds($ttl)
638638
*
639639
* @return string|null
640640
*/
641-
protected function getName()
641+
public function getName()
642642
{
643643
return $this->config['store'] ?? null;
644644
}

tests/Integration/Queue/UniqueJobTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Exception;
66
use Illuminate\Bus\Queueable;
7+
use Illuminate\Container\Container;
78
use Illuminate\Contracts\Cache\Repository as Cache;
89
use Illuminate\Contracts\Queue\ShouldBeUnique;
910
use Illuminate\Contracts\Queue\ShouldBeUniqueUntilProcessing;
@@ -51,6 +52,14 @@ public function testUniqueJobsAreNotDispatched()
5152
);
5253
}
5354

55+
public function testUniqueJobWithViaDispatched()
56+
{
57+
Bus::fake();
58+
59+
UniqueViaJob::dispatch();
60+
Bus::assertDispatched(UniqueViaJob::class);
61+
}
62+
5463
public function testLockIsReleasedForSuccessfulJobs()
5564
{
5665
UniqueTestJob::$handled = false;
@@ -222,3 +231,11 @@ public function __construct(public User $user)
222231
{
223232
}
224233
}
234+
235+
class UniqueViaJob extends UniqueTestJob
236+
{
237+
public function uniqueVia(): Cache
238+
{
239+
return Container::getInstance()->make(Cache::class);
240+
}
241+
}

0 commit comments

Comments
 (0)