This commit is contained in:
Alex Renoki 2020-08-23 18:34:29 +03:00
parent 96c0eb98d6
commit b46cfadaa2
6 changed files with 48 additions and 19 deletions

View File

@ -45,7 +45,7 @@ jobs:
- name: Install dependencies
run: |
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench:${{ matrix.testbench }}" --no-interaction --no-update
composer require "laravel/framework:${{ matrix.laravel }}" "orchestra/testbench-browser-kit:${{ matrix.testbench }}" --no-interaction --no-update
composer update --${{ matrix.dependency-version }} --prefer-dist --no-interaction --no-suggest
- name: Execute tests with Local driver

View File

@ -42,7 +42,7 @@
},
"require-dev": {
"mockery/mockery": "^1.3",
"orchestra/testbench": "3.8.*|^4.0|^5.0",
"orchestra/testbench-browser-kit": "^4.0|^5.0",
"phpunit/phpunit": "^8.0|^9.0"
},
"autoload": {

View File

@ -45,10 +45,10 @@ class RedisPusherBroadcaster extends Broadcaster
/**
* Create a new broadcaster instance.
*
* @param Pusher $pusher
* @param $appId
* @param \Illuminate\Contracts\Redis\Factory $redis
* @param string|null $connection
* @param Pusher $pusher
* @param mixed $appId
* @param \Illuminate\Contracts\Redis\Factory $redis
* @param string|null $connection
*/
public function __construct(Pusher $pusher, $appId, Redis $redis, $connection = null)
{
@ -63,7 +63,6 @@ class RedisPusherBroadcaster extends Broadcaster
*
* @param \Illuminate\Http\Request $request
* @return mixed
*
* @throws \Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException
*/
public function auth($request)
@ -83,8 +82,8 @@ class RedisPusherBroadcaster extends Broadcaster
/**
* Return the valid authentication response.
*
* @param \Illuminate\Http\Request $request
* @param mixed $result
* @param \Illuminate\Http\Request $request
* @param mixed $result
* @return mixed
* @throws \Pusher\PusherException
*/
@ -144,7 +143,7 @@ class RedisPusherBroadcaster extends Broadcaster
]);
foreach ($this->formatChannels($channels) as $channel) {
$connection->publish("{$this->appId}:$channel", $payload);
$connection->publish("{$this->appId}:{$channel}", $payload);
}
}
}

View File

@ -118,13 +118,15 @@ class WebSocketsServiceProvider extends ServiceProvider
*/
protected function registerDashboardRoutes()
{
Route::prefix(config('websockets.dashboard.path'))->group(function () {
Route::middleware(config('websockets.dashboard.middleware', [AuthorizeDashboard::class]))->group(function () {
Route::get('/', ShowDashboard::class);
Route::get('/api/{appId}/statistics', [DashboardApiController::class, 'getStatistics']);
Route::post('auth', AuthenticateDashboard::class);
Route::post('event', SendMessage::class);
});
Route::group([
'prefix' => config('websockets.dashboard.path'),
'as' => 'laravel-websockets.',
'middleware' => config('websockets.dashboard.middleware', [AuthorizeDashboard::class]),
], function () {
Route::get('/', ShowDashboard::class)->name('dashboard');
Route::get('/api/{appId}/statistics', [DashboardApiController::class, 'getStatistics'])->name('statistics');
Route::post('auth', AuthenticateDashboard::class)->name('auth');
Route::post('event', SendMessage::class)->name('send');
});
return $this;
@ -138,7 +140,7 @@ class WebSocketsServiceProvider extends ServiceProvider
protected function registerDashboardGate()
{
Gate::define('viewWebSocketsDashboard', function ($user = null) {
return $this->app->environment('local');
return $this->app->environment(['local', 'testing']);
});
return $this;

View File

@ -0,0 +1,25 @@
<?php
namespace BeyondCode\LaravelWebSockets\Tests\Dashboard;
use BeyondCode\LaravelWebSockets\Tests\TestCase;
class DashboardTest extends TestCase
{
/** @test */
public function cant_see_dashboard_without_authorization()
{
config(['app.env' => 'production']);
$this->get(route('laravel-websockets.dashboard'))
->assertResponseStatus(403);
}
/** @test */
public function can_see_dashboard()
{
$this->get(route('laravel-websockets.dashboard'))
->assertResponseOk()
->see('WebSockets Dashboard');
}
}

View File

@ -12,10 +12,11 @@ use BeyondCode\LaravelWebSockets\Tests\Mocks\Message;
use BeyondCode\LaravelWebSockets\Tests\Statistics\Logger\FakeStatisticsLogger;
use BeyondCode\LaravelWebSockets\WebSockets\Channels\ChannelManager;
use GuzzleHttp\Psr7\Request;
use Orchestra\Testbench\BrowserKit\TestCase as BaseTestCase;
use Ratchet\ConnectionInterface;
use React\EventLoop\Factory as LoopFactory;
abstract class TestCase extends \Orchestra\Testbench\TestCase
abstract class TestCase extends BaseTestCase
{
/**
* A test Pusher server.
@ -76,6 +77,8 @@ abstract class TestCase extends \Orchestra\Testbench\TestCase
*/
protected function getEnvironmentSetUp($app)
{
$app['config']->set('app.key', 'wslxrEFGWY6GfGhvN9L3wH3KSRJQQpBD');
$app['config']->set('websockets.apps', [
[
'name' => 'Test App',