legacy = new WebSocketHandler($this->channelManager); } public function test_unknown_app_key_gets_4001_and_is_closed() { $connection = $this->newConnection('NonWorkingKey'); $this->legacy->onOpen($connection); $connection ->assertSentEvent('websocket.error', [ 'data' => ['message' => 'Could not find app key `NonWorkingKey`.', 'code' => 4001], ]) ->assertNotSentEvent('websocket.connection_established') ->assertClosed(); $this->assertSame(4001, $connection->closeCode); $this->assertFalse(isset($connection->app)); } public function test_array_app_key_gets_4001_and_is_closed() { $connection = new Mocks\Connection; $connection->httpRequest = new Request('GET', '/?appKey[]=x'); $this->legacy->onOpen($connection); $connection ->assertSentEvent('websocket.error', ['data' => ['message' => 'Could not find app key ``.', 'code' => 4001]]) ->assertClosed(); $this->assertSame(4001, $connection->closeCode); } public function test_disallowed_origin_gets_4009_and_is_closed() { $connection = $this->newConnection('TestOrigin', ['Origin' => 'https://google.ro']); $this->legacy->onOpen($connection); $connection ->assertSentEvent('websocket.error', [ 'data' => ['message' => 'The origin is not allowed for `TestOrigin`.', 'code' => 4009], ]) ->assertNotSentEvent('websocket.connection_established') ->assertClosed(); $this->assertSame(4009, $connection->closeCode); } public function test_known_app_key_is_established_and_stays_open() { $connection = $this->newConnection(); $this->legacy->onOpen($connection); $connection->assertSentEvent('websocket.connection_established'); $this->assertFalse($connection->closed); $this->assertSame('TestKey', $connection->app->key); } }