diff --git a/tests/AppStatsTest.php b/tests/AppStatsTest.php index 9da633f..d6e37de 100644 --- a/tests/AppStatsTest.php +++ b/tests/AppStatsTest.php @@ -98,7 +98,7 @@ public function testAppstatsMinute0() { "start" => self::$timestampMs, "end" => self::$timestampMs ]); - $this->assertEquals( 1, count( $stats->items ), "Expected 1 record" ); + $this->assertCount(1, $stats->items, "Expected 1 record"); $this->assertEquals( 50, $stats->items[0]->inbound->all->all->count, "Expected 50 messages" ); $stats = self::$ably->stats([ @@ -106,7 +106,7 @@ public function testAppstatsMinute0() { "start" => self::$timestampMs + $oneMinuteMs, "end" => self::$timestampMs + $oneMinuteMs ]); - $this->assertEquals( 1, count( $stats->items ), "Expected 1 record" ); + $this->assertCount(1, $stats->items, "Expected 1 record"); $this->assertEquals( 60, $stats->items[0]->inbound->all->all->count, "Expected 60 messages" ); $stats = self::$ably->stats([ @@ -114,7 +114,7 @@ public function testAppstatsMinute0() { "start" => self::$timestampMs + $twoMinutesMs, "end" => self::$timestampMs + $twoMinutesMs ]); - $this->assertEquals( 1, count( $stats->items ), "Expected 1 record" ); + $this->assertCount(1, $stats->items, "Expected 1 record"); $this->assertEquals( 70, $stats->items[0]->inbound->all->all->count, "Expected 70 messages" ); } @@ -131,7 +131,7 @@ public function testAppstatsMinute1() { "start" => self::$timestampMs, "end" => self::$timestampMs ]); - $this->assertEquals( 1, count( $stats->items ), "Expected 1 record" ); + $this->assertCount(1, $stats->items, "Expected 1 record"); $this->assertEquals( 50, $stats->items[0]->inbound->all->all->count, "Expected 50 messages" ); $stats = self::$ably->stats([ @@ -139,7 +139,7 @@ public function testAppstatsMinute1() { "start" => self::$timestampMs + $oneMinuteMs, "end" => self::$timestampMs + $oneMinuteMs ]); - $this->assertEquals( 1, count( $stats->items ), "Expected 1 record" ); + $this->assertCount(1, $stats->items, "Expected 1 record"); $this->assertEquals( 60, $stats->items[0]->inbound->all->all->count, "Expected 60 messages" ); $stats = self::$ably->stats([ @@ -147,7 +147,7 @@ public function testAppstatsMinute1() { "start" => self::$timestampMs + $twoMinutesMs, "end" => self::$timestampMs + $twoMinutesMs ]); - $this->assertEquals( 1, count( $stats->items ), "Expected 1 record" ); + $this->assertCount(1, $stats->items, "Expected 1 record"); $this->assertEquals( 70, $stats->items[0]->inbound->all->all->count, "Expected 70 messages" ); } @@ -162,7 +162,7 @@ public function testAppstatsHour0() { "end" => self::$timestampMs + $twoMinutesMs, "unit" => "hour" ]); - $this->assertEquals( 1, count( $stats->items ), "Expected 1 record" ); + $this->assertCount(1, $stats->items, "Expected 1 record"); $this->assertEquals( 180, $stats->items[0]->inbound->all->all->count, "Expected 180 messages" ); } @@ -177,7 +177,7 @@ public function testAppstatsDay0() { "end" => self::$timestampMs + $twoMinutesMs, "unit" => "day" ]); - $this->assertEquals( 1, count( $stats->items ), "Expected 1 record" ); + $this->assertCount(1, $stats->items, "Expected 1 record"); $this->assertEquals( 180, $stats->items[0]->inbound->all->all->count, "Expected 180 messages" ); } @@ -193,7 +193,7 @@ public function testAppstatsMonth0() { "unit" => "month" ]); - $this->assertEquals( 1, count( $stats->items ), "Expected 1 record" ); + $this->assertCount(1, $stats->items, "Expected 1 record"); $this->assertEquals( 180, $stats->items[0]->inbound->all->all->count, "Expected 180 messages" ); } @@ -208,7 +208,7 @@ public function testAppstatsLimit0() { "end" => self::$timestampMs + $twoMinutesMs, "limit" => 1 ]); - $this->assertEquals( 1, count( $stats->items ), "Expected 1 record" ); + $this->assertCount(1, $stats->items, "Expected 1 record"); $this->assertEquals( 70, $stats->items[0]->inbound->all->all->count, "Expected 70 messages" ); } @@ -223,7 +223,7 @@ public function testAppstatsLimit1() { "end" => self::$timestampMs + $twoMinutesMs, "limit" => 1 ]); - $this->assertEquals( 1, count( $stats->items ), "Expected 1 record" ); + $this->assertCount(1, $stats->items, "Expected 1 record"); $this->assertEquals( 50, $stats->items[0]->inbound->all->all->count, "Expected 50 messages" ); } @@ -238,15 +238,15 @@ public function testAppstatsPagination0() { "end" => self::$timestampMs + $twoMinutesMs, "limit" => 1 ]); - $this->assertEquals( 1, count( $stats->items ), "Expected 1 record" ); + $this->assertCount(1, $stats->items, "Expected 1 record"); $this->assertEquals( 70, $stats->items[0]->inbound->all->all->count, "Expected 70 messages" ); // get next page $stats = $stats->next(); - $this->assertEquals( 1, count( $stats->items ), "Expected 1 record" ); + $this->assertCount(1, $stats->items, "Expected 1 record"); $this->assertEquals( 60, $stats->items[0]->inbound->all->all->count, "Expected 60 messages" ); // get next page $stats = $stats->next(); - $this->assertEquals( 1, count( $stats->items ), "Expected 1 record" ); + $this->assertCount(1, $stats->items, "Expected 1 record"); $this->assertEquals( 50, $stats->items[0]->inbound->all->all->count, "Expected 50 messages" ); // verify that there is no next page $this->assertFalse( $stats->hasNext(), "Expected not to have next page" ); @@ -264,15 +264,15 @@ public function testAppstatsPagination1() { "end" => self::$timestampMs + $twoMinutesMs, "limit" => 1 ]); - $this->assertEquals( 1, count( $stats->items ), "Expected 1 record" ); + $this->assertCount(1, $stats->items, "Expected 1 record"); $this->assertEquals( 50, $stats->items[0]->inbound->all->all->count, "Expected 50 messages" ); // get next page $stats = $stats->next(); - $this->assertEquals( 1, count( $stats->items ), "Expected 1 record" ); + $this->assertCount(1, $stats->items, "Expected 1 record"); $this->assertEquals( 60, $stats->items[0]->inbound->all->all->count, "Expected 60 messages" ); // get next page $stats = $stats->next(); - $this->assertEquals( 1, count( $stats->items ), "Expected 1 record" ); + $this->assertCount(1, $stats->items, "Expected 1 record"); $this->assertEquals( 70, $stats->items[0]->inbound->all->all->count, "Expected 70 messages" ); // verify that there is no next page $this->assertFalse( $stats->hasNext(), "Expected not to have next page" ); @@ -290,15 +290,15 @@ public function testAppstatsPagination2() { "end" => self::$timestampMs + $twoMinutesMs, "limit" => 1 ]); - $this->assertEquals( 1, count( $stats->items ), "Expected 1 record" ); + $this->assertCount(1, $stats->items, "Expected 1 record"); $this->assertEquals( 70, $stats->items[0]->inbound->all->all->count, "Expected 70 messages" ); // get next page $stats = $stats->next(); - $this->assertEquals( 1, count( $stats->items ), "Expected 1 record" ); + $this->assertCount(1, $stats->items, "Expected 1 record"); $this->assertEquals( 60, $stats->items[0]->inbound->all->all->count, "Expected 60 messages" ); // get first page $stats = $stats->first(); - $this->assertEquals( 1, count( $stats->items ), "Expected 1 record" ); + $this->assertCount(1, $stats->items, "Expected 1 record"); $this->assertEquals( 70, $stats->items[0]->inbound->all->all->count, "Expected 70 messages" ); } @@ -313,15 +313,15 @@ public function testAppstatsPagination3() { "end" => self::$timestampMs + $twoMinutesMs, "limit" => 1 ]); - $this->assertEquals( 1, count( $stats->items ), "Expected 1 record" ); + $this->assertCount(1, $stats->items, "Expected 1 record"); $this->assertEquals( 50, $stats->items[0]->inbound->all->all->count, "Expected 50 messages" ); // get next page $stats = $stats->next(); - $this->assertEquals( 1, count( $stats->items ), "Expected 1 record" ); + $this->assertCount(1, $stats->items, "Expected 1 record"); $this->assertEquals( 60, $stats->items[0]->inbound->all->all->count, "Expected 60 messages" ); // get first page $stats = $stats->first(); - $this->assertEquals( 1, count( $stats->items ), "Expected 1 record" ); + $this->assertCount(1, $stats->items, "Expected 1 record"); $this->assertEquals( 50, $stats->items[0]->inbound->all->all->count, "Expected 50 messages" ); } @@ -334,7 +334,7 @@ public function testPaginationDefaults () { "start" => self::$timestampOlderMs, "end" => self::$timestampOlderMs + $twoHoursMs, ]); - $this->assertEquals( 100, count( $stats->items ), "Expected 100 records" ); + $this->assertCount(100, $stats->items, "Expected 100 records"); // verify order $actualRecordsPeakData = []; @@ -344,4 +344,4 @@ public function testPaginationDefaults () { $expectedData = range( 101, 2, -1 ); $this->assertEquals( $expectedData, $actualRecordsPeakData, 'Expected records in backward order' ); } -} \ No newline at end of file +} diff --git a/tests/AuthTest.php b/tests/AuthTest.php index 0da208c..eba9ca4 100644 --- a/tests/AuthTest.php +++ b/tests/AuthTest.php @@ -404,7 +404,7 @@ public function testCreateTokenRequestParams() { 'Unexpected values in TokenRequest built from ClientOptions + TokenParams + AuthOptions' ); $this->assertNotNull( $tokenRequest->mac, 'Expected hmac to be generated' ); - $this->assertTrue( $ablyKey->http->timeQueried, 'Expected server to be queried for time' ); + $this->assertTrue( (bool)$ablyKey->http->timeQueried, 'Expected server to be queried for time' ); $ablyKey->http->timeQueried = false; } @@ -425,7 +425,7 @@ public function testAuthorize() { $tokenOriginal = $ably->auth->authorize(); - $this->assertTrue( $ably->auth->requestTokenCalled, 'Expected authorize() to call requestToken()' ); + $this->assertTrue( (bool)$ably->auth->requestTokenCalled, 'Expected authorize() to call requestToken()' ); $this->assertFalse( $ably->auth->isUsingBasicAuth(), 'Expected token auth to be used' ); $this->assertInstanceOf( 'Ably\Models\TokenDetails', $tokenOriginal, @@ -469,7 +469,7 @@ public function testAuthorizeParams() { // test with empty params first $ably->auth->authorize(); - $this->assertTrue( $ably->auth->requestTokenCalled, 'Expected authorize() to call requestToken()' ); + $this->assertTrue( (bool)$ably->auth->requestTokenCalled, 'Expected authorize() to call requestToken()' ); $this->assertEmpty( $ably->auth->lastTokenParams, 'Expected authorize() to pass empty tokenParams to requestToken()'); $this->assertEmpty( $ably->auth->lastAuthOptions, diff --git a/tests/ChannelHistoryTest.php b/tests/ChannelHistoryTest.php index 74ebb45..a9c82b7 100644 --- a/tests/ChannelHistoryTest.php +++ b/tests/ChannelHistoryTest.php @@ -42,7 +42,7 @@ public function testPublishEventsAndCheckOrderForwards() { // get the history for this channel $messages = $history1->history( ['direction' => 'forwards'] ); - $this->assertEquals( 50, count($messages->items), 'Expected 50 messages' ); + $this->assertCount(50, $messages->items, 'Expected 50 messages'); // verify message order $actual_message_history = []; @@ -70,7 +70,7 @@ public function testPublishEventsAndCheckOrderBackwards() { $history2->publish( $msgsToSend ); $messages = $history2->history( ['direction' => 'backwards'] ); - $this->assertEquals( 50, count($messages->items), 'Expected 50 messages' ); + $this->assertCount(50, $messages->items, 'Expected 50 messages'); // verify message order $actual_message_history = []; @@ -96,7 +96,7 @@ public function testDefaults() { $channel->publish( $msgsToSend ); $messages = $channel->history(); - $this->assertEquals( 100, count( $messages->items ), 'Expected 100 messages' ); + $this->assertCount(100, $messages->items, 'Expected 100 messages'); // verify message order $actual_message_history = []; @@ -124,7 +124,7 @@ public function testPublishEventsGetLimitedHistoryAndCheckOrderForwards() { $history3->publish( $msgsToSend ); $messages = $history3->history( ['direction' => 'forwards', 'limit' => 25] ); - $this->assertEquals( 25, count($messages->items), 'Expected 25 messages' ); + $this->assertCount(25, $messages->items, 'Expected 25 messages'); // verify message order $actual_message_history = []; @@ -142,7 +142,7 @@ public function testPublishEventsGetLimitedHistoryAndCheckOrderForwards() { // next page $messages2 = $messages->next(); - $this->assertEquals( 25, count($messages2->items), 'Expected 25 messages on 2nd page' ); + $this->assertCount(25, $messages2->items, 'Expected 25 messages on 2nd page'); $actual_message_history2 = []; foreach ($messages2->items as $msg) { @@ -159,7 +159,7 @@ public function testPublishEventsGetLimitedHistoryAndCheckOrderForwards() { // get the first page from the 2nd page $messages1 = $messages2->first(); - $this->assertEquals( 25, count($messages1->items), 'Expected 25 messages on the 1st page' ); + $this->assertCount(25, $messages1->items, 'Expected 25 messages on the 1st page'); $actual_message_history1 = []; foreach ($messages1->items as $msg) { @@ -186,7 +186,7 @@ public function testPublishEventsGetLimitedHistoryAndCheckOrderBackwards() { $history4->publish( $msgsToSend ); $messages = $history4->history( ['direction' => 'backwards', 'limit' => 25] ); - $this->assertEquals( 25, count($messages->items), 'Expected 25 messages' ); + $this->assertCount(25, $messages->items, 'Expected 25 messages'); // verify message order $actual_message_history = []; @@ -204,7 +204,7 @@ public function testPublishEventsGetLimitedHistoryAndCheckOrderBackwards() { // next page $messages2 = $messages->next(); - $this->assertEquals( 25, count($messages2->items), 'Expected 25 messages on 2nd page' ); + $this->assertCount(25, $messages2->items, 'Expected 25 messages on 2nd page'); $actual_message_history2 = []; foreach ($messages2->items as $msg) { @@ -226,7 +226,7 @@ public function testPublishEventsGetLimitedHistoryAndCheckOrderBackwards() { // get the first page from the 2nd page $messages1 = $messages2->first(); - $this->assertEquals( 25, count($messages1->items), 'Expected 25 messages on the 1st page' ); + $this->assertCount(25, $messages1->items, 'Expected 25 messages on the 1st page'); $actual_message_history1 = []; foreach ($messages1->items as $msg) { @@ -266,7 +266,7 @@ public function testPublishEventsAndCheckExpectedHistoryInTimeSlicesForwards() { 'start' => $interval_start, 'end' => $interval_end, ]); - $this->assertEquals( 2, count($messages->items), 'Expected 2 messages' ); + $this->assertCount(2, $messages->items, 'Expected 2 messages'); // verify message order $actual_message_history = []; @@ -309,7 +309,7 @@ public function testPublishEventsAndCheckExpectedHistoryInTimeSlicesBackwards() 'end' => $interval_end, ]); - $this->assertEquals( 2, count($messages->items), 'Expected 20 messages' ); + $this->assertCount(2, $messages->items, 'Expected 20 messages'); // verify message order $actual_message_history = []; diff --git a/tests/ChannelIdempotentTest.php b/tests/ChannelIdempotentTest.php index 9ad18ee..6925d3e 100644 --- a/tests/ChannelIdempotentTest.php +++ b/tests/ChannelIdempotentTest.php @@ -88,13 +88,13 @@ public function testIdempotentLibraryGenerated() { $body = json_decode($body); $id = explode ( ":", $body->id); - $this->assertEquals( count($id), 2); + $this->assertCount(2, $id); $this->assertGreaterThanOrEqual( 9, strlen(base64_decode($id[0])) ); - $this->assertEquals( $id[1], "0"); + $this->assertEquals( "0", $id[1]); $channel->publish($msg); $messages = $channel->history(); - $this->assertEquals(1, count($messages->items)); + $this->assertCount(1, $messages->items); $this->assertEquals($messages->items[0]->id, $msg->id); } @@ -117,11 +117,11 @@ public function testIdempotentClientSupplied() { else $body = json_decode($body); - $this->assertEquals( $body->id, "foobar" ); + $this->assertEquals( "foobar", $body->id); $channel->publish($msg); $messages = $channel->history(); - $this->assertEquals(count($messages->items), 1); + $this->assertCount(1, $messages->items); $this->assertEquals($messages->items[0]->id, $msg->id); } @@ -152,7 +152,7 @@ public function testIdempotentMixedIds() { else $body = json_decode($body); - $this->assertEquals( $body[0]->id, "foobar" ); + $this->assertEquals( "foobar", $body[0]->id); $this->assertFalse( property_exists($body[1], 'id') ); $this->expectException(AblyRequestException::class); @@ -180,10 +180,11 @@ public function testIdempotentLibraryGeneratedPublish() { $msg->name = 'name'; $msg->data = 'data'; - $body = $channel->publish( $msg ); + $channel->publish( $msg ); $messages = $channel->history(); - $this->assertEquals( 1, count($messages->items)); + sleep(2); + $this->assertCount(1, $messages->items); } /** @@ -202,7 +203,7 @@ public function testIdempotentClientSuppliedPublish() { $body = $channel->publish( $msg ); $messages = $channel->history(); - $this->assertEquals( 1, count($messages->items)); + $this->assertCount(1, $messages->items); } }