Merge branch '2.x' of github.com:beyondcode/laravel-websockets into refactor/tests
This commit is contained in:
commit
279dd62a31
|
|
@ -10,15 +10,13 @@ jobs:
|
||||||
matrix:
|
matrix:
|
||||||
os: [ubuntu-latest, windows-latest]
|
os: [ubuntu-latest, windows-latest]
|
||||||
php: [7.4, 7.3, 7.2]
|
php: [7.4, 7.3, 7.2]
|
||||||
laravel: [5.8.*, 6.*, 7.*]
|
laravel: [6.*, 7.*]
|
||||||
dependency-version: [prefer-lowest, prefer-stable]
|
dependency-version: [prefer-lowest, prefer-stable]
|
||||||
include:
|
include:
|
||||||
- laravel: 7.*
|
- laravel: 7.*
|
||||||
testbench: 5.*
|
testbench: 5.*
|
||||||
- laravel: 6.*
|
- laravel: 6.*
|
||||||
testbench: 4.*
|
testbench: 4.*
|
||||||
- laravel: 5.8.*
|
|
||||||
testbench: 3.8.*
|
|
||||||
|
|
||||||
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}
|
name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -29,11 +29,11 @@
|
||||||
"clue/redis-react": "^2.3",
|
"clue/redis-react": "^2.3",
|
||||||
"facade/ignition-contracts": "^1.0",
|
"facade/ignition-contracts": "^1.0",
|
||||||
"guzzlehttp/psr7": "^1.5",
|
"guzzlehttp/psr7": "^1.5",
|
||||||
"illuminate/broadcasting": "5.8.*|^6.0|^7.0",
|
"illuminate/broadcasting": "^6.0|^7.0",
|
||||||
"illuminate/console": "5.8.*|^6.0|^7.0",
|
"illuminate/console": "^6.0|^7.0",
|
||||||
"illuminate/http": "5.8.*|^6.0|^7.0",
|
"illuminate/http": "^6.0|^7.0",
|
||||||
"illuminate/routing": "5.8.*|^6.0|^7.0",
|
"illuminate/routing": "^6.0|^7.0",
|
||||||
"illuminate/support": "5.8.*|^6.0|^7.0",
|
"illuminate/support": "^6.0|^7.0",
|
||||||
"pusher/pusher-php-server": "^3.0|^4.0",
|
"pusher/pusher-php-server": "^3.0|^4.0",
|
||||||
"react/dns": "^1.1",
|
"react/dns": "^1.1",
|
||||||
"symfony/http-kernel": "^4.0|^5.0",
|
"symfony/http-kernel": "^4.0|^5.0",
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ return [
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'app' => \BeyondCode\LaravelWebSockets\Apps\ConfigAppProvider::class,
|
'app' => \BeyondCode\LaravelWebSockets\Apps\ConfigAppManager::class,
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|
@ -195,7 +195,7 @@ return [
|
||||||
|
|
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
'logger' => \BeyondCode\LaravelWebSockets\Statistics\Logger::class,
|
'logger' => BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger::class,
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -118,7 +118,7 @@
|
||||||
wssPort: this.port === null ? 6001 : this.port,
|
wssPort: this.port === null ? 6001 : this.port,
|
||||||
wsPath: this.app.path === null ? '' : this.app.path,
|
wsPath: this.app.path === null ? '' : this.app.path,
|
||||||
disableStats: true,
|
disableStats: true,
|
||||||
authEndpoint: '{{ url('/auth') }}',
|
authEndpoint: '{{ url(request()->path().'/auth') }}',
|
||||||
auth: {
|
auth: {
|
||||||
headers: {
|
headers: {
|
||||||
'X-CSRF-Token': "{{ csrf_token() }}",
|
'X-CSRF-Token': "{{ csrf_token() }}",
|
||||||
|
|
@ -162,7 +162,7 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
loadChart() {
|
loadChart() {
|
||||||
$.getJSON('{{ url('/api') }}/' + this.app.id + '/statistics', (data) => {
|
$.getJSON('{{ url(request()->path().'/api') }}/' + this.app.id + '/statistics', (data) => {
|
||||||
|
|
||||||
let chartData = [
|
let chartData = [
|
||||||
{
|
{
|
||||||
|
|
@ -246,7 +246,7 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
sendEvent() {
|
sendEvent() {
|
||||||
$.post('{{ url('/event') }}', {
|
$.post('{{ url(request()->path().'/event') }}', {
|
||||||
_token: '{{ csrf_token() }}',
|
_token: '{{ csrf_token() }}',
|
||||||
key: this.app.key,
|
key: this.app.key,
|
||||||
secret: this.app.secret,
|
secret: this.app.secret,
|
||||||
|
|
|
||||||
|
|
@ -35,17 +35,17 @@ class App
|
||||||
|
|
||||||
public static function findById($appId)
|
public static function findById($appId)
|
||||||
{
|
{
|
||||||
return app(AppProvider::class)->findById($appId);
|
return app(AppManager::class)->findById($appId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function findByKey(string $appKey): ?self
|
public static function findByKey(string $appKey): ?self
|
||||||
{
|
{
|
||||||
return app(AppProvider::class)->findByKey($appKey);
|
return app(AppManager::class)->findByKey($appKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function findBySecret(string $appSecret): ?self
|
public static function findBySecret(string $appSecret): ?self
|
||||||
{
|
{
|
||||||
return app(AppProvider::class)->findBySecret($appSecret);
|
return app(AppManager::class)->findBySecret($appSecret);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function __construct($appId, string $appKey, string $appSecret)
|
public function __construct($appId, string $appKey, string $appSecret)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace BeyondCode\LaravelWebSockets\Apps;
|
namespace BeyondCode\LaravelWebSockets\Apps;
|
||||||
|
|
||||||
interface AppProvider
|
interface AppManager
|
||||||
{
|
{
|
||||||
/** @return array[BeyondCode\LaravelWebSockets\AppProviders\App] */
|
/** @return array[BeyondCode\LaravelWebSockets\AppProviders\App] */
|
||||||
public function all(): array;
|
public function all(): array;
|
||||||
|
|
@ -4,7 +4,7 @@ namespace BeyondCode\LaravelWebSockets\Apps;
|
||||||
|
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
|
||||||
class ConfigAppProvider implements AppProvider
|
class ConfigAppManager implements AppManager
|
||||||
{
|
{
|
||||||
/** @var Collection */
|
/** @var Collection */
|
||||||
protected $apps;
|
protected $apps;
|
||||||
|
|
@ -14,7 +14,7 @@ class ConfigAppProvider implements AppProvider
|
||||||
$this->apps = collect(config('websockets.apps'));
|
$this->apps = collect(config('websockets.apps'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @return array[\BeyondCode\LaravelWebSockets\AppProviders\App] */
|
/** @return array[\BeyondCode\LaravelWebSockets\Apps\App] */
|
||||||
public function all(): array
|
public function all(): array
|
||||||
{
|
{
|
||||||
return $this->apps
|
return $this->apps
|
||||||
|
|
@ -69,7 +69,7 @@ class StartWebSocketServer extends Command
|
||||||
$browser = new Browser($this->loop, $connector);
|
$browser = new Browser($this->loop, $connector);
|
||||||
|
|
||||||
$this->laravel->singleton(StatisticsLoggerInterface::class, function () use ($browser) {
|
$this->laravel->singleton(StatisticsLoggerInterface::class, function () use ($browser) {
|
||||||
$class = config('websockets.statistics.logger', \BeyondCode\LaravelWebSockets\Statistics\Logger::class);
|
$class = config('websockets.statistics.logger', \BeyondCode\LaravelWebSockets\Statistics\Logger\HttpStatisticsLogger::class);
|
||||||
|
|
||||||
return new $class(
|
return new $class(
|
||||||
$this->laravel->make(ChannelManager::class),
|
$this->laravel->make(ChannelManager::class),
|
||||||
|
|
|
||||||
|
|
@ -2,12 +2,12 @@
|
||||||
|
|
||||||
namespace BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers;
|
namespace BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers;
|
||||||
|
|
||||||
use BeyondCode\LaravelWebSockets\Apps\AppProvider;
|
use BeyondCode\LaravelWebSockets\Apps\AppManager;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
class ShowDashboard
|
class ShowDashboard
|
||||||
{
|
{
|
||||||
public function __invoke(Request $request, AppProvider $apps)
|
public function __invoke(Request $request, AppManager $apps)
|
||||||
{
|
{
|
||||||
return view('websockets::dashboard', [
|
return view('websockets::dashboard', [
|
||||||
'apps' => $apps->all(),
|
'apps' => $apps->all(),
|
||||||
|
|
|
||||||
|
|
@ -2,20 +2,20 @@
|
||||||
|
|
||||||
namespace BeyondCode\LaravelWebSockets\Statistics\Rules;
|
namespace BeyondCode\LaravelWebSockets\Statistics\Rules;
|
||||||
|
|
||||||
use BeyondCode\LaravelWebSockets\Apps\AppProvider;
|
use BeyondCode\LaravelWebSockets\Apps\AppManager;
|
||||||
use Illuminate\Contracts\Validation\Rule;
|
use Illuminate\Contracts\Validation\Rule;
|
||||||
|
|
||||||
class AppId implements Rule
|
class AppId implements Rule
|
||||||
{
|
{
|
||||||
public function passes($attribute, $value)
|
public function passes($attribute, $value)
|
||||||
{
|
{
|
||||||
$appProvider = app(AppProvider::class);
|
$manager = app(AppManager::class);
|
||||||
|
|
||||||
return $appProvider->findById($value) ? true : false;
|
return $manager->findById($value) ? true : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function message()
|
public function message()
|
||||||
{
|
{
|
||||||
return 'There is no app registered with the given id. Make sure the websockets config file contains an app for this id or that your custom AppProvider returns an app for this id.';
|
return 'There is no app registered with the given id. Make sure the websockets config file contains an app for this id or that your custom AppManager returns an app for this id.';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
namespace BeyondCode\LaravelWebSockets;
|
namespace BeyondCode\LaravelWebSockets;
|
||||||
|
|
||||||
use BeyondCode\LaravelWebSockets\Apps\AppProvider;
|
use BeyondCode\LaravelWebSockets\Apps\AppManager;
|
||||||
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\AuthenticateDashboard;
|
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\AuthenticateDashboard;
|
||||||
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\DashboardApiController;
|
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\DashboardApiController;
|
||||||
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\SendMessage;
|
use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\SendMessage;
|
||||||
|
|
@ -101,7 +101,7 @@ class WebSocketsServiceProvider extends ServiceProvider
|
||||||
return new $channelManager;
|
return new $channelManager;
|
||||||
});
|
});
|
||||||
|
|
||||||
$this->app->singleton(AppProvider::class, function () {
|
$this->app->singleton(AppManager::class, function () {
|
||||||
return $this->app->make(config('websockets.managers.app'));
|
return $this->app->make(config('websockets.managers.app'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,25 +2,25 @@
|
||||||
|
|
||||||
namespace BeyondCode\LaravelWebSockets\Tests\ClientProviders;
|
namespace BeyondCode\LaravelWebSockets\Tests\ClientProviders;
|
||||||
|
|
||||||
use BeyondCode\LaravelWebSockets\Apps\ConfigAppProvider;
|
use BeyondCode\LaravelWebSockets\Apps\ConfigAppManager;
|
||||||
use BeyondCode\LaravelWebSockets\Tests\TestCase;
|
use BeyondCode\LaravelWebSockets\Tests\TestCase;
|
||||||
|
|
||||||
class ConfigAppProviderTest extends TestCase
|
class ConfigAppManagerTest extends TestCase
|
||||||
{
|
{
|
||||||
/** @var \BeyondCode\LaravelWebSockets\Apps\ConfigAppProvider */
|
/** @var \BeyondCode\LaravelWebSockets\Apps\ConfigAppManager */
|
||||||
protected $configAppProvider;
|
protected $appManager;
|
||||||
|
|
||||||
public function setUp(): void
|
public function setUp(): void
|
||||||
{
|
{
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
|
||||||
$this->configAppProvider = new ConfigAppProvider();
|
$this->appManager = new ConfigAppManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
public function it_can_get_apps_from_the_config_file()
|
public function it_can_get_apps_from_the_config_file()
|
||||||
{
|
{
|
||||||
$apps = $this->configAppProvider->all();
|
$apps = $this->appManager->all();
|
||||||
|
|
||||||
$this->assertCount(1, $apps);
|
$this->assertCount(1, $apps);
|
||||||
|
|
||||||
|
|
@ -38,11 +38,11 @@ class ConfigAppProviderTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function it_can_find_app_by_id()
|
public function it_can_find_app_by_id()
|
||||||
{
|
{
|
||||||
$app = $this->configAppProvider->findById(0000);
|
$app = $this->appManager->findById(0000);
|
||||||
|
|
||||||
$this->assertNull($app);
|
$this->assertNull($app);
|
||||||
|
|
||||||
$app = $this->configAppProvider->findById(1234);
|
$app = $this->appManager->findById(1234);
|
||||||
|
|
||||||
$this->assertEquals('Test App', $app->name);
|
$this->assertEquals('Test App', $app->name);
|
||||||
$this->assertEquals(1234, $app->id);
|
$this->assertEquals(1234, $app->id);
|
||||||
|
|
@ -55,11 +55,11 @@ class ConfigAppProviderTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function it_can_find_app_by_key()
|
public function it_can_find_app_by_key()
|
||||||
{
|
{
|
||||||
$app = $this->configAppProvider->findByKey('InvalidKey');
|
$app = $this->appManager->findByKey('InvalidKey');
|
||||||
|
|
||||||
$this->assertNull($app);
|
$this->assertNull($app);
|
||||||
|
|
||||||
$app = $this->configAppProvider->findByKey('TestKey');
|
$app = $this->appManager->findByKey('TestKey');
|
||||||
|
|
||||||
$this->assertEquals('Test App', $app->name);
|
$this->assertEquals('Test App', $app->name);
|
||||||
$this->assertEquals(1234, $app->id);
|
$this->assertEquals(1234, $app->id);
|
||||||
|
|
@ -72,11 +72,11 @@ class ConfigAppProviderTest extends TestCase
|
||||||
/** @test */
|
/** @test */
|
||||||
public function it_can_find_app_by_secret()
|
public function it_can_find_app_by_secret()
|
||||||
{
|
{
|
||||||
$app = $this->configAppProvider->findBySecret('InvalidSecret');
|
$app = $this->appManager->findBySecret('InvalidSecret');
|
||||||
|
|
||||||
$this->assertNull($app);
|
$this->assertNull($app);
|
||||||
|
|
||||||
$app = $this->configAppProvider->findBySecret('TestSecret');
|
$app = $this->appManager->findBySecret('TestSecret');
|
||||||
|
|
||||||
$this->assertEquals('Test App', $app->name);
|
$this->assertEquals('Test App', $app->name);
|
||||||
$this->assertEquals(1234, $app->id);
|
$this->assertEquals(1234, $app->id);
|
||||||
Loading…
Reference in New Issue