diff --git a/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php b/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php index f9af4e15ee..14a1222e79 100644 --- a/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php +++ b/tests/e2e/Services/Realtime/RealtimeCustomClientTest.php @@ -181,21 +181,14 @@ class RealtimeCustomClientTest extends Scope $client = $this->getWebsocket(['account'], [ 'origin' => 'http://localhost' ], timeout: 10); - $assertResponseEventually = function (callable $assertion) use ($client): void { - $this->assertEventually(function () use ($client, $assertion) { - $response = \json_decode($client->receive(), true); - $this->assertIsArray($response); - $assertion($response); - }, 10000, 250); - }; - $assertResponseEventually(function (array $response): void { - $this->assertArrayHasKey('type', $response); - $this->assertArrayHasKey('data', $response); - $this->assertEquals('connected', $response['type']); - $this->assertNotEmpty($response['data']); - $this->assertCount(1, $response['data']['channels']); - $this->assertContains('account', $response['data']['channels']); - }); + $response = json_decode($client->receive(), true); + + $this->assertArrayHasKey('type', $response); + $this->assertArrayHasKey('data', $response); + $this->assertEquals('connected', $response['type']); + $this->assertNotEmpty($response['data']); + $this->assertCount(1, $response['data']['channels']); + $this->assertContains('account', $response['data']['channels']); $client->send(\json_encode([ 'type' => 'authentication', @@ -204,16 +197,16 @@ class RealtimeCustomClientTest extends Scope ] ])); - $assertResponseEventually(function (array $response) use ($userId): void { - $this->assertArrayHasKey('type', $response); - $this->assertArrayHasKey('data', $response); - $this->assertEquals('response', $response['type']); - $this->assertNotEmpty($response['data']); - $this->assertEquals('authentication', $response['data']['to']); - $this->assertTrue($response['data']['success']); - $this->assertNotEmpty($response['data']['user']); - $this->assertEquals($userId, $response['data']['user']['$id']); - }); + $response = json_decode($client->receive(), true); + + $this->assertArrayHasKey('type', $response); + $this->assertArrayHasKey('data', $response); + $this->assertEquals('response', $response['type']); + $this->assertNotEmpty($response['data']); + $this->assertEquals('authentication', $response['data']['to']); + $this->assertTrue($response['data']['success']); + $this->assertNotEmpty($response['data']['user']); + $this->assertEquals($userId, $response['data']['user']['$id']); /** * Test for FAILURE @@ -225,28 +218,28 @@ class RealtimeCustomClientTest extends Scope ] ])); - $assertResponseEventually(function (array $response): void { - $this->assertArrayHasKey('type', $response); - $this->assertArrayHasKey('data', $response); - $this->assertEquals('error', $response['type']); - $this->assertNotEmpty($response['data']); - $this->assertEquals(1003, $response['data']['code']); - $this->assertEquals('Session is not valid.', $response['data']['message']); - }); + $response = json_decode($client->receive(), true); + + $this->assertArrayHasKey('type', $response); + $this->assertArrayHasKey('data', $response); + $this->assertEquals('error', $response['type']); + $this->assertNotEmpty($response['data']); + $this->assertEquals(1003, $response['data']['code']); + $this->assertEquals('Session is not valid.', $response['data']['message']); $client->send(\json_encode([ 'type' => 'authentication', 'data' => [] ])); - $assertResponseEventually(function (array $response): void { - $this->assertArrayHasKey('type', $response); - $this->assertArrayHasKey('data', $response); - $this->assertEquals('error', $response['type']); - $this->assertNotEmpty($response['data']); - $this->assertEquals(1003, $response['data']['code']); - $this->assertEquals('Payload is not valid.', $response['data']['message']); - }); + $response = json_decode($client->receive(), true); + + $this->assertArrayHasKey('type', $response); + $this->assertArrayHasKey('data', $response); + $this->assertEquals('error', $response['type']); + $this->assertNotEmpty($response['data']); + $this->assertEquals(1003, $response['data']['code']); + $this->assertEquals('Payload is not valid.', $response['data']['message']); $client->send(\json_encode([ 'type' => 'unknown', @@ -255,27 +248,27 @@ class RealtimeCustomClientTest extends Scope ] ])); - $assertResponseEventually(function (array $response): void { - $this->assertArrayHasKey('type', $response); - $this->assertArrayHasKey('data', $response); - $this->assertEquals('error', $response['type']); - $this->assertNotEmpty($response['data']); - $this->assertEquals(1003, $response['data']['code']); - $this->assertEquals('Message type is not valid.', $response['data']['message']); - }); + $response = json_decode($client->receive(), true); + + $this->assertArrayHasKey('type', $response); + $this->assertArrayHasKey('data', $response); + $this->assertEquals('error', $response['type']); + $this->assertNotEmpty($response['data']); + $this->assertEquals(1003, $response['data']['code']); + $this->assertEquals('Message type is not valid.', $response['data']['message']); $client->send(\json_encode([ 'test' => '123', ])); - $assertResponseEventually(function (array $response): void { - $this->assertArrayHasKey('type', $response); - $this->assertArrayHasKey('data', $response); - $this->assertEquals('error', $response['type']); - $this->assertNotEmpty($response['data']); - $this->assertEquals(1003, $response['data']['code']); - $this->assertEquals('Message format is not valid.', $response['data']['message']); - }); + $response = json_decode($client->receive(), true); + + $this->assertArrayHasKey('type', $response); + $this->assertArrayHasKey('data', $response); + $this->assertEquals('error', $response['type']); + $this->assertNotEmpty($response['data']); + $this->assertEquals(1003, $response['data']['code']); + $this->assertEquals('Message format is not valid.', $response['data']['message']); $client->close();