From 03be8f3e68097a346c4a31c5fdb164671fafa5f5 Mon Sep 17 00:00:00 2001 From: everlCode <82755522+everlCode@users.noreply.github.com> Date: Wed, 16 Oct 2024 20:06:27 +0300 Subject: [PATCH] Support batch api method (#67) --- src/Client.php | 11 +++++++++++ tests/ClientTest.php | 28 +++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 1 deletion(-) diff --git a/src/Client.php b/src/Client.php index b3a4bfe..3c0cd6c 100644 --- a/src/Client.php +++ b/src/Client.php @@ -294,6 +294,17 @@ public function info() return $this->send('info'); } + /** + * Sending many commands in one request + * + * @param array $data + * @return mixed + */ + public function batch(array $data) + { + return $this->send('batch', $data); + } + /** * Generate connection JWT. See https://centrifugal.dev/docs/server/authentication. * Keep in mind that this method does not support all claims of Centrifugo JWT connection diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 840acca..7b5f878 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -68,7 +68,11 @@ public function testPublishNetworkError() { $this->expectException(Exception::class); $client = new \phpcent\Client("http://localhost:9000/api"); - $res = $client->publish('channel', ["message" => "Hello World"]); + + $client->setConnectTimeoutOption(5); + $client->setTimeoutOption(15); + + $client->publish('channel', ["message" => "Hello World"]); } public function testInfo() @@ -77,4 +81,26 @@ public function testInfo() $this->assertNotNull($res); $this->assertTrue(is_array($res->result->nodes)); } + + public function testBatch() + { + $data = [ + "commands" => [ + [ + "presence_stats" => [ + "channel" => "test1" + ] + ], + [ + "publish" => [ + "channel" => "x:test2", + "data" => [] + ] + ] + ] + ]; + + $res = $this->client->batch($data); + $this->assertIsArray($res->replies); + } }