Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit b46cfad

Browse files
committed
wip
1 parent 96c0eb9 commit b46cfad

File tree

6 files changed

+48
-19
lines changed

6 files changed

+48
-19
lines changed

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545

4646
- name: Install dependencies
4747
run: |
48-
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
48+
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench-browser-kit:${{ matrix.testbench }}" --no-interaction --no-update
4949
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
5050
5151
- name: Execute tests with Local driver

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
},
4343
"require-dev": {
4444
"mockery/mockery": "^1.3",
45-
"orchestra/testbench": "3.8.*|^4.0|^5.0",
45+
"orchestra/testbench-browser-kit": "^4.0|^5.0",
4646
"phpunit/phpunit": "^8.0|^9.0"
4747
},
4848
"autoload": {

src/PubSub/Broadcasters/RedisPusherBroadcaster.php

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ class RedisPusherBroadcaster extends Broadcaster
4545
/**
4646
* Create a new broadcaster instance.
4747
*
48-
* @param Pusher $pusher
49-
* @param $appId
50-
* @param \Illuminate\Contracts\Redis\Factory $redis
51-
* @param string|null $connection
48+
* @param Pusher $pusher
49+
* @param mixed $appId
50+
* @param \Illuminate\Contracts\Redis\Factory $redis
51+
* @param string|null $connection
5252
*/
5353
public function __construct(Pusher $pusher, $appId, Redis $redis, $connection = null)
5454
{
@@ -63,7 +63,6 @@ public function __construct(Pusher $pusher, $appId, Redis $redis, $connection =
6363
*
6464
* @param \Illuminate\Http\Request $request
6565
* @return mixed
66-
*
6766
* @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
6867
*/
6968
public function auth($request)
@@ -83,8 +82,8 @@ public function auth($request)
8382
/**
8483
* Return the valid authentication response.
8584
*
86-
* @param \Illuminate\Http\Request $request
87-
* @param mixed $result
85+
* @param \Illuminate\Http\Request $request
86+
* @param mixed $result
8887
* @return mixed
8988
* @throws \Pusher\PusherException
9089
*/
@@ -144,7 +143,7 @@ public function broadcast(array $channels, $event, array $payload = [])
144143
]);
145144

146145
foreach ($this->formatChannels($channels) as $channel) {
147-
$connection->publish("{$this->appId}:$channel", $payload);
146+
$connection->publish("{$this->appId}:{$channel}", $payload);
148147
}
149148
}
150149
}

src/WebSocketsServiceProvider.php

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -118,13 +118,15 @@ protected function configurePubSub()
118118
*/
119119
protected function registerDashboardRoutes()
120120
{
121-
Route::prefix(config('websockets.dashboard.path'))->group(function () {
122-
Route::middleware(config('websockets.dashboard.middleware', [AuthorizeDashboard::class]))->group(function () {
123-
Route::get('/', ShowDashboard::class);
124-
Route::get('/api/{appId}/statistics', [DashboardApiController::class, 'getStatistics']);
125-
Route::post('auth', AuthenticateDashboard::class);
126-
Route::post('event', SendMessage::class);
127-
});
121+
Route::group([
122+
'prefix' => config('websockets.dashboard.path'),
123+
'as' => 'laravel-websockets.',
124+
'middleware' => config('websockets.dashboard.middleware', [AuthorizeDashboard::class]),
125+
], function () {
126+
Route::get('/', ShowDashboard::class)->name('dashboard');
127+
Route::get('/api/{appId}/statistics', [DashboardApiController::class, 'getStatistics'])->name('statistics');
128+
Route::post('auth', AuthenticateDashboard::class)->name('auth');
129+
Route::post('event', SendMessage::class)->name('send');
128130
});
129131

130132
return $this;
@@ -138,7 +140,7 @@ protected function registerDashboardRoutes()
138140
protected function registerDashboardGate()
139141
{
140142
Gate::define('viewWebSocketsDashboard', function ($user = null) {
141-
return $this->app->environment('local');
143+
return $this->app->environment(['local', 'testing']);
142144
});
143145

144146
return $this;

tests/Dashboard/DashboardTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
namespace BeyondCode\LaravelWebSockets\Tests\Dashboard;
4+
5+
use BeyondCode\LaravelWebSockets\Tests\TestCase;
6+
7+
class DashboardTest extends TestCase
8+
{
9+
/** @test */
10+
public function cant_see_dashboard_without_authorization()
11+
{
12+
config(['app.env' => 'production']);
13+
14+
$this->get(route('laravel-websockets.dashboard'))
15+
->assertResponseStatus(403);
16+
}
17+
18+
/** @test */
19+
public function can_see_dashboard()
20+
{
21+
$this->get(route('laravel-websockets.dashboard'))
22+
->assertResponseOk()
23+
->see('WebSockets Dashboard');
24+
}
25+
}

tests/TestCase.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,11 @@
1212
use BeyondCode\LaravelWebSockets\Tests\Statistics\Logger\FakeStatisticsLogger;
1313
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
1414
use GuzzleHttp\Psr7\Request;
15+
use Orchestra\Testbench\BrowserKit\TestCase as BaseTestCase;
1516
use Ratchet\ConnectionInterface;
1617
use React\EventLoop\Factory as LoopFactory;
1718

18-
abstract class TestCase extends \Orchestra\Testbench\TestCase
19+
abstract class TestCase extends BaseTestCase
1920
{
2021
/**
2122
* A test Pusher server.
@@ -76,6 +77,8 @@ protected function getPackageProviders($app)
7677
*/
7778
protected function getEnvironmentSetUp($app)
7879
{
80+
$app['config']->set('app.key', 'wslxrEFGWY6GfGhvN9L3wH3KSRJQQpBD');
81+
7982
$app['config']->set('websockets.apps', [
8083
[
8184
'name' => 'Test App',

0 commit comments

Comments
 (0)