Skip to content

Commit 9d517b6

Browse files
committed
Update UniqueBroadcastEvent to work with displayName() in lock key
1 parent 02edfc9 commit 9d517b6

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

src/Illuminate/Broadcasting/UniqueBroadcastEvent.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@ class UniqueBroadcastEvent extends BroadcastEvent implements ShouldBeUnique
2929
*/
3030
public function __construct($event)
3131
{
32-
$this->uniqueId = get_class($event);
33-
3432
if (method_exists($event, 'uniqueId')) {
3533
$this->uniqueId .= $event->uniqueId();
3634
} elseif (property_exists($event, 'uniqueId')) {

tests/Integration/Broadcasting/BroadcastManagerTest.php

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,35 @@ public function testUniqueEventsCanBeBroadcast()
7575
Bus::assertNotDispatched(UniqueBroadcastEvent::class);
7676
Queue::assertPushed(UniqueBroadcastEvent::class);
7777

78-
$lockKey = 'laravel_unique_job:'.UniqueBroadcastEvent::class.':'.TestEventUnique::class;
78+
$lockKey = 'laravel_unique_job:'.TestEventUnique::class.':';
79+
$this->assertFalse($this->app->get(Cache::class)->lock($lockKey, 10)->get());
80+
}
81+
82+
public function testUniqueEventsCanBeBroadcastWithUniqueIdFromProperty()
83+
{
84+
Bus::fake();
85+
Queue::fake();
86+
87+
Broadcast::queue(new TestEventUniqueWithIdProperty);
88+
89+
Bus::assertNotDispatched(UniqueBroadcastEvent::class);
90+
Queue::assertPushed(UniqueBroadcastEvent::class);
91+
92+
$lockKey = 'laravel_unique_job:'.TestEventUniqueWithIdProperty::class.':unique-id-property';
93+
$this->assertFalse($this->app->get(Cache::class)->lock($lockKey, 10)->get());
94+
}
95+
96+
public function testUniqueEventsCanBeBroadcastWithUniqueIdFromMethod()
97+
{
98+
Bus::fake();
99+
Queue::fake();
100+
101+
Broadcast::queue(new TestEventUniqueWithIdMethod);
102+
103+
Bus::assertNotDispatched(UniqueBroadcastEvent::class);
104+
Queue::assertPushed(UniqueBroadcastEvent::class);
105+
106+
$lockKey = 'laravel_unique_job:'.TestEventUniqueWithIdMethod::class.':unique-id-method';
79107
$this->assertFalse($this->app->get(Cache::class)->lock($lockKey, 10)->get());
80108
}
81109

@@ -178,6 +206,16 @@ public function broadcastOn()
178206
}
179207
}
180208

209+
class TestEventUniqueWithIdProperty extends TestEventUnique
210+
{
211+
public string $uniqueId = 'unique-id-property';
212+
}
213+
214+
class TestEventUniqueWithIdMethod extends TestEventUnique
215+
{
216+
public string $uniqueId = 'unique-id-method';
217+
}
218+
181219
class TestEventRescue implements ShouldBroadcast, ShouldRescue
182220
{
183221
/**

0 commit comments

Comments
 (0)