2018-12-01 13:12:15 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace BeyondCode\LaravelWebSockets\Tests\ClientProviders;
|
|
|
|
|
|
2020-08-13 11:51:18 +00:00
|
|
|
use BeyondCode\LaravelWebSockets\Apps\ConfigAppManager;
|
2020-03-04 09:58:39 +00:00
|
|
|
use BeyondCode\LaravelWebSockets\Tests\TestCase;
|
2018-12-01 13:12:15 +00:00
|
|
|
|
2020-08-13 11:51:18 +00:00
|
|
|
class ConfigAppManagerTest extends TestCase
|
2018-12-01 13:12:15 +00:00
|
|
|
{
|
2020-08-13 11:51:18 +00:00
|
|
|
/** @var \BeyondCode\LaravelWebSockets\Apps\ConfigAppManager */
|
|
|
|
|
protected $appManager;
|
2018-12-01 13:12:15 +00:00
|
|
|
|
2019-02-27 14:27:21 +00:00
|
|
|
public function setUp(): void
|
2018-12-01 13:12:15 +00:00
|
|
|
{
|
|
|
|
|
parent::setUp();
|
|
|
|
|
|
2020-08-13 11:51:18 +00:00
|
|
|
$this->appManager = new ConfigAppManager;
|
2018-12-01 13:12:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @test */
|
2018-12-01 13:17:32 +00:00
|
|
|
public function it_can_get_apps_from_the_config_file()
|
2018-12-01 13:12:15 +00:00
|
|
|
{
|
2020-08-13 11:51:18 +00:00
|
|
|
$apps = $this->appManager->all();
|
2018-12-01 13:12:15 +00:00
|
|
|
|
2020-08-18 13:07:35 +00:00
|
|
|
$this->assertCount(2, $apps);
|
2018-12-01 13:12:15 +00:00
|
|
|
|
2018-12-04 21:22:33 +00:00
|
|
|
/** @var $app */
|
2018-12-01 13:17:32 +00:00
|
|
|
$app = $apps[0];
|
2018-12-01 13:12:15 +00:00
|
|
|
|
2018-12-01 13:17:32 +00:00
|
|
|
$this->assertEquals('Test App', $app->name);
|
|
|
|
|
$this->assertEquals(1234, $app->id);
|
|
|
|
|
$this->assertEquals('TestKey', $app->key);
|
|
|
|
|
$this->assertEquals('TestSecret', $app->secret);
|
2018-12-01 15:24:36 +00:00
|
|
|
$this->assertFalse($app->clientMessagesEnabled);
|
2018-12-03 10:58:42 +00:00
|
|
|
$this->assertTrue($app->statisticsEnabled);
|
2018-12-01 13:12:15 +00:00
|
|
|
}
|
2018-12-04 09:15:37 +00:00
|
|
|
|
|
|
|
|
/** @test */
|
|
|
|
|
public function it_can_find_app_by_id()
|
|
|
|
|
{
|
2020-08-13 11:51:18 +00:00
|
|
|
$app = $this->appManager->findById(0000);
|
2018-12-04 09:15:37 +00:00
|
|
|
|
|
|
|
|
$this->assertNull($app);
|
|
|
|
|
|
2020-08-13 11:51:18 +00:00
|
|
|
$app = $this->appManager->findById(1234);
|
2018-12-04 09:15:37 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals('Test App', $app->name);
|
|
|
|
|
$this->assertEquals(1234, $app->id);
|
|
|
|
|
$this->assertEquals('TestKey', $app->key);
|
|
|
|
|
$this->assertEquals('TestSecret', $app->secret);
|
|
|
|
|
$this->assertFalse($app->clientMessagesEnabled);
|
|
|
|
|
$this->assertTrue($app->statisticsEnabled);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @test */
|
|
|
|
|
public function it_can_find_app_by_key()
|
|
|
|
|
{
|
2020-08-13 11:51:18 +00:00
|
|
|
$app = $this->appManager->findByKey('InvalidKey');
|
2018-12-04 09:15:37 +00:00
|
|
|
|
|
|
|
|
$this->assertNull($app);
|
|
|
|
|
|
2020-08-13 11:51:18 +00:00
|
|
|
$app = $this->appManager->findByKey('TestKey');
|
2018-12-04 09:15:37 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals('Test App', $app->name);
|
|
|
|
|
$this->assertEquals(1234, $app->id);
|
|
|
|
|
$this->assertEquals('TestKey', $app->key);
|
|
|
|
|
$this->assertEquals('TestSecret', $app->secret);
|
|
|
|
|
$this->assertFalse($app->clientMessagesEnabled);
|
|
|
|
|
$this->assertTrue($app->statisticsEnabled);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @test */
|
|
|
|
|
public function it_can_find_app_by_secret()
|
|
|
|
|
{
|
2020-08-13 11:51:18 +00:00
|
|
|
$app = $this->appManager->findBySecret('InvalidSecret');
|
2018-12-04 09:15:37 +00:00
|
|
|
|
|
|
|
|
$this->assertNull($app);
|
|
|
|
|
|
2020-08-13 11:51:18 +00:00
|
|
|
$app = $this->appManager->findBySecret('TestSecret');
|
2018-12-04 09:15:37 +00:00
|
|
|
|
|
|
|
|
$this->assertEquals('Test App', $app->name);
|
|
|
|
|
$this->assertEquals(1234, $app->id);
|
|
|
|
|
$this->assertEquals('TestKey', $app->key);
|
|
|
|
|
$this->assertEquals('TestSecret', $app->secret);
|
|
|
|
|
$this->assertFalse($app->clientMessagesEnabled);
|
|
|
|
|
$this->assertTrue($app->statisticsEnabled);
|
|
|
|
|
}
|
2018-12-04 21:22:33 +00:00
|
|
|
}
|