From 481e3486b2e15bbed583ea1cfea9b72dd625055f Mon Sep 17 00:00:00 2001 From: sacOO7 Date: Wed, 10 Apr 2024 17:31:55 +0530 Subject: [PATCH] Added explicit test for rest batch publish --- tests/AblyRestRequestTest.php | 65 +++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 tests/AblyRestRequestTest.php diff --git a/tests/AblyRestRequestTest.php b/tests/AblyRestRequestTest.php new file mode 100644 index 0000000..6ef57ab --- /dev/null +++ b/tests/AblyRestRequestTest.php @@ -0,0 +1,65 @@ +getOptions(); + self::$ably = new AblyRest( array_merge( self::$defaultOptions, [ + 'key' => self::$testApp->getAppKeyDefault()->string, + ] ) ); + } + + public static function tearDownAfterClass(): void { + self::$testApp->release(); + } + + /** + * Batch publishes messages for given list of channels + * RSC19 + * https://ably.com/docs/api/rest-api#batch-publish + * @throws \Ably\Exceptions\AblyRequestException + */ + public function testBatchPublishMultipleChannelsUsingPostRequest() { + + $payload = array( + "channels" => ["channel1", "channel2", "channel3", "channel4"], + "messages" => array( + "id" => "1", + "data" => "foo" + ) + ); + + $batchPublishPaginatedResult = self::$ably->request("POST","/messages", [], $payload); + $this->assertNotNull($batchPublishPaginatedResult); + $this->assertEquals(201, $batchPublishPaginatedResult->statusCode); + $this->assertTrue($batchPublishPaginatedResult->success); + $this->assertNull($batchPublishPaginatedResult->errorCode); + $this->assertNull($batchPublishPaginatedResult->errorMessage); + $this->assertTrue( $batchPublishPaginatedResult->isLast(), 'Expected not to be the last page' ); + + $this->assertEquals("application/x-msgpack", $batchPublishPaginatedResult->headers["Content-Type"]); + $this->assertCount(4, $batchPublishPaginatedResult->items); + foreach ($batchPublishPaginatedResult->items as $key=> $item) { + $this->assertEquals("channel".($key + 1), $item->channel); + $this->assertEquals(1, $item->messageId); + } + + foreach (["channel1", "channel2", "channel3", "channel4"] as $channelName) { + print $channelName; + $channel = self::$ably->channel($channelName); + $paginatedHistory = $channel->history(); + foreach ($paginatedHistory->items as $msg) { + $this->assertEquals("1", $msg->id); + $this->assertEquals("foo", $msg->data); + } + } + } +}