Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/Illuminate/Broadcasting/BroadcastManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
use InvalidArgumentException;
use Psr\Log\LoggerInterface;
use Pusher\Pusher;
use RuntimeException;
use Throwable;

/**
* @mixin \Illuminate\Contracts\Broadcasting\Broadcaster
Expand Down Expand Up @@ -292,7 +294,11 @@ protected function resolve($name)
throw new InvalidArgumentException("Driver [{$config['driver']}] is not supported.");
}

return $this->{$driverMethod}($config);
try {
return $this->{$driverMethod}($config);
} catch (Throwable $e) {
throw new RuntimeException("Failed to create broadcaster for connection \"{$name}\" with error: {$e->getMessage()}.", 0, $e);
}
}

/**
Expand Down
31 changes: 31 additions & 0 deletions tests/Integration/Broadcasting/BroadcastManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Tests\Integration\Broadcasting;

use Illuminate\Broadcasting\BroadcastEvent;
use Illuminate\Broadcasting\BroadcastException;
use Illuminate\Broadcasting\BroadcastManager;
use Illuminate\Broadcasting\UniqueBroadcastEvent;
use Illuminate\Config\Repository;
Expand All @@ -17,6 +18,7 @@
use Illuminate\Support\Facades\Queue;
use InvalidArgumentException;
use Orchestra\Testbench\TestCase;
use RuntimeException;

class BroadcastManagerTest extends TestCase
{
Expand Down Expand Up @@ -100,6 +102,35 @@ public function testThrowExceptionWhenUnknownStoreIsUsed()
$broadcastManager->connection('alien_connection');
}

public function testThrowExceptionWhenDriverCreationFails()
{
$userConfig = [
'broadcasting' => [
'connections' => [
'log_connection_1' => [
'driver' => 'log',
],
],
],
];

$app = $this->getApp($userConfig);
$app->singleton(\Psr\Log\LoggerInterface::class, function () {
throw new \RuntimeException('Logger service not available');
});

$broadcastManager = new BroadcastManager($app);

try {
$broadcastManager->connection('log_connection_1');
$this->fail('Expected BroadcastException was not thrown');
} catch (RuntimeException $e) {
$this->assertStringContainsString('Failed to create broadcaster for connection "log_connection_1"', $e->getMessage());
$this->assertStringContainsString('Logger service not available', $e->getMessage());
$this->assertInstanceOf(\RuntimeException::class, $e->getPrevious());
}
}

protected function getApp(array $userConfig)
{
$app = new Container;
Expand Down