Skip to content

Commit

Permalink
refactored test files with right assert statements
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Mar 22, 2024
1 parent 973b599 commit a646592
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 47 deletions.
50 changes: 25 additions & 25 deletions tests/AppStatsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,23 @@ 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([
"direction" => "forwards",
"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([
"direction" => "forwards",
"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" );
}

Expand All @@ -131,23 +131,23 @@ 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([
"direction" => "backwards",
"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([
"direction" => "backwards",
"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" );
}

Expand All @@ -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" );
}

Expand All @@ -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" );
}

Expand All @@ -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" );
}

Expand All @@ -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" );
}

Expand All @@ -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" );
}

Expand All @@ -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" );
Expand All @@ -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" );
Expand All @@ -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" );
}

Expand All @@ -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" );
}

Expand All @@ -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 = [];
Expand All @@ -344,4 +344,4 @@ public function testPaginationDefaults () {
$expectedData = range( 101, 2, -1 );
$this->assertEquals( $expectedData, $actualRecordsPeakData, 'Expected records in backward order' );
}
}
}
6 changes: 3 additions & 3 deletions tests/AuthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
22 changes: 11 additions & 11 deletions tests/ChannelHistoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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 = [];
Expand All @@ -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 = [];
Expand Down Expand Up @@ -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 = [];
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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 = [];
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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 = [];
Expand Down Expand Up @@ -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 = [];
Expand Down
16 changes: 8 additions & 8 deletions tests/ChannelIdempotentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -184,7 +184,7 @@ public function testIdempotentLibraryGeneratedPublish() {

$messages = $channel->history();
sleep(2);
$this->assertEquals( 1, count($messages->items));
$this->assertCount(1, $messages->items);
}

/**
Expand All @@ -203,7 +203,7 @@ public function testIdempotentClientSuppliedPublish() {
$body = $channel->publish( $msg );

$messages = $channel->history();
$this->assertEquals( 1, count($messages->items));
$this->assertCount(1, $messages->items);
}

}

0 comments on commit a646592

Please sign in to comment.