Skip to content

Commit ec3958d

Browse files
authored
throw exception when broadcast connection not configured (#44745)
1 parent c06913f commit ec3958d

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

src/Illuminate/Broadcasting/BroadcastManager.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,10 @@ protected function resolve($name)
245245
{
246246
$config = $this->getConfig($name);
247247

248+
if (is_null($config)) {
249+
throw new InvalidArgumentException("Broadcast connection [{$name}] is not defined.");
250+
}
251+
248252
if (isset($this->customCreators[$config['driver']])) {
249253
return $this->callCustomCreator($config);
250254
}

tests/Integration/Broadcasting/BroadcastManagerTest.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,18 @@
33
namespace Illuminate\Tests\Integration\Broadcasting;
44

55
use Illuminate\Broadcasting\BroadcastEvent;
6+
use Illuminate\Broadcasting\BroadcastManager;
67
use Illuminate\Broadcasting\UniqueBroadcastEvent;
8+
use Illuminate\Config\Repository;
9+
use Illuminate\Container\Container;
710
use Illuminate\Contracts\Broadcasting\ShouldBeUnique;
811
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
912
use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow;
1013
use Illuminate\Contracts\Cache\Repository as Cache;
1114
use Illuminate\Support\Facades\Broadcast;
1215
use Illuminate\Support\Facades\Bus;
1316
use Illuminate\Support\Facades\Queue;
17+
use InvalidArgumentException;
1418
use Orchestra\Testbench\TestCase;
1519

1620
class BroadcastManagerTest extends TestCase
@@ -50,6 +54,36 @@ public function testUniqueEventsCanBeBroadcast()
5054
$lockKey = 'laravel_unique_job:'.UniqueBroadcastEvent::class.TestEventUnique::class;
5155
$this->assertFalse($this->app->get(Cache::class)->lock($lockKey, 10)->get());
5256
}
57+
58+
public function testThrowExceptionWhenUnknownStoreIsUsed()
59+
{
60+
$this->expectException(InvalidArgumentException::class);
61+
$this->expectExceptionMessage('Broadcast connection [alien_connection] is not defined.');
62+
63+
$userConfig = [
64+
'broadcasting' => [
65+
'connections' => [
66+
'my_connection' => [
67+
'driver' => 'pusher',
68+
],
69+
],
70+
],
71+
];
72+
73+
$app = $this->getApp($userConfig);
74+
75+
$broadcastManager = new BroadcastManager($app);
76+
77+
$broadcastManager->connection('alien_connection');
78+
}
79+
80+
protected function getApp(array $userConfig)
81+
{
82+
$app = new Container;
83+
$app->singleton('config', fn () => new Repository($userConfig));
84+
85+
return $app;
86+
}
5387
}
5488

5589
class TestEvent implements ShouldBroadcast

0 commit comments

Comments
 (0)