Skip to content

Commit

Permalink
Improve assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
peter279k committed Sep 21, 2023
1 parent 1ae9999 commit 4eb19a0
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 40 deletions.
6 changes: 3 additions & 3 deletions tests/CustomModelsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function it_can_use_custom_table(): void
$this->setMessageCustomModel();
$this->setMessageCustomTable();

$this->assertEquals('custom_messages', Models::table('messages'));
$this->assertSame('custom_messages', Models::table('messages'));

$this->unsetMessageCustomModel();
$this->unsetMessageCustomTable();
Expand All @@ -53,15 +53,15 @@ public function it_should_return_custom_name_when_not_available(): void
{
$modelName = 'ModelNotFound';

$this->assertEquals('ModelNotFound', Models::classname($modelName));
$this->assertSame('ModelNotFound', Models::classname($modelName));
}

/** :TODO: test */
public function it_can_get_custom_model_table_property(): void
{
$this->setMessageCustomModel();

$this->assertEquals('custom_messages', Models::message()->getTable());
$this->assertSame('custom_messages', Models::message()->getTable());

$this->unsetMessageCustomModel();
}
Expand Down
2 changes: 1 addition & 1 deletion tests/EloquentMessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public function it_should_get_the_recipients_of_a_message(): void

$thread->participants()->saveMany([$user_1, $user_2, $user_3]);

$this->assertEquals(2, $message->recipients()->count());
$this->assertSame(2, $message->recipients()->count());
}
}
66 changes: 33 additions & 33 deletions tests/EloquentThreadTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public function search_specific_thread_by_subject(): void

$threads = Thread::getBySubject('first subject');

$this->assertEquals(1, $threads->count());
$this->assertEquals(1, $threads->first()->id);
$this->assertEquals('first subject', $threads->first()->subject);
$this->assertSame(1, $threads->count());
$this->assertSame(1, $threads->first()->id);
$this->assertSame('first subject', $threads->first()->subject);
}

/** @test */
Expand All @@ -52,23 +52,23 @@ public function search_threads_by_subject(): void

$threads = Thread::getBySubject('%subject');

$this->assertEquals(2, $threads->count());
$this->assertSame(2, $threads->count());

$this->assertEquals(1, $threads->first()->id);
$this->assertEquals('first subject', $threads->first()->subject);
$this->assertSame(1, $threads->first()->id);
$this->assertSame('first subject', $threads->first()->subject);

$this->assertEquals(2, $threads->last()->id);
$this->assertEquals('second subject', $threads->last()->subject);
$this->assertSame(2, $threads->last()->id);
$this->assertSame('second subject', $threads->last()->subject);
}

/** @test */
public function it_should_create_a_new_thread(): void
{
$thread = $this->threadFactory();
$this->assertEquals('Sample thread', $thread->subject);
$this->assertSame('Sample thread', $thread->subject);

$thread = $this->threadFactory(['subject' => 'Second sample thread']);
$this->assertEquals('Second sample thread', $thread->subject);
$this->assertSame('Second sample thread', $thread->subject);
}

/** @test */
Expand All @@ -85,7 +85,7 @@ public function it_should_return_the_latest_message(): void

$thread = $this->threadFactory();
$thread->messages()->saveMany([$oldMessage, $newMessage]);
$this->assertEquals($newMessage->body, $thread->latestMessage->body);
$this->assertSame($newMessage->body, $thread->latestMessage->body);
}

/** @test */
Expand Down Expand Up @@ -117,11 +117,11 @@ public function it_should_get_all_thread_participants(): void

$participantIds = $thread->participantsUserIds();
$this->assertCount(3, $participantIds);
$this->assertEquals(2, $participantIds[1]);
$this->assertSame(2, (int)$participantIds[1]);

$participantIds = $thread->participantsUserIds(999);
$this->assertCount(4, $participantIds);
$this->assertEquals(999, end($participantIds));
$this->assertSame(999, end($participantIds));

$this->assertIsArray($participantIds);
}
Expand Down Expand Up @@ -254,7 +254,7 @@ public function it_should_add_a_participant_to_a_thread(): void

$thread->addParticipant($participant);

$this->assertEquals(1, $thread->participants()->count());
$this->assertSame(1, $thread->participants()->count());
}

/** @test */
Expand All @@ -266,7 +266,7 @@ public function it_should_add_participants_to_a_thread_with_array(): void

$thread->addParticipant($participants);

$this->assertEquals(3, $thread->participants()->count());
$this->assertSame(3, $thread->participants()->count());
}

/** @test */
Expand All @@ -276,7 +276,7 @@ public function it_should_add_participants_to_a_thread_with_arguments(): void

$thread->addParticipant(1, 2);

$this->assertEquals(2, $thread->participants()->count());
$this->assertSame(2, $thread->participants()->count());
}

/** @test */
Expand All @@ -291,7 +291,7 @@ public function it_should_mark_the_participant_as_read(): void

$thread->markAsRead($userId);

$this->assertNotEquals($thread->getParticipantFromUser($userId)->last_read, $last_read);
$this->assertNotSame($thread->getParticipantFromUser($userId)->last_read, $last_read);
}

/** @test */
Expand Down Expand Up @@ -355,12 +355,12 @@ public function it_should_activate_all_deleted_participants(): void
$thread->participants()->saveMany([$user_1, $user_2, $user_3]);

$participants = $thread->participants();
$this->assertEquals(0, $participants->count());
$this->assertSame(0, $participants->count());

$thread->activateAllParticipants();

$participants = $thread->participants();
$this->assertEquals(3, $participants->count());
$this->assertSame(3, $participants->count());
}

/** @test */
Expand All @@ -375,18 +375,18 @@ public function it_should_generate_participant_select_string(): void
$expectedString = '(' . Eloquent::getConnectionResolver()->getTablePrefix() . $tableName . '.name) as name';

if (config('database.connections.testbench.driver') === 'mysql') {
$this->assertEquals('concat' . $expectedString, $select);
$this->assertSame('concat' . $expectedString, $select);
} else {
$this->assertEquals($expectedString, $select);
$this->assertSame($expectedString, $select);
}

$columns = ['name', 'email'];
$select = $method->invokeArgs($thread, [$columns]);

if (config('database.connections.testbench.driver') === 'mysql') {
$this->assertEquals('concat(' . Eloquent::getConnectionResolver()->getTablePrefix() . $tableName . ".name, ' ', " . Eloquent::getConnectionResolver()->getTablePrefix() . $tableName . '.email) as name', $select);
$this->assertSame('concat(' . Eloquent::getConnectionResolver()->getTablePrefix() . $tableName . ".name, ' ', " . Eloquent::getConnectionResolver()->getTablePrefix() . $tableName . '.email) as name', $select);
} else {
$this->assertEquals('(' . Eloquent::getConnectionResolver()->getTablePrefix() . $tableName . ".name || ' ' || " . Eloquent::getConnectionResolver()->getTablePrefix() . $tableName . '.email) as name', $select);
$this->assertSame('(' . Eloquent::getConnectionResolver()->getTablePrefix() . $tableName . ".name || ' ' || " . Eloquent::getConnectionResolver()->getTablePrefix() . $tableName . '.email) as name', $select);
}
}

Expand All @@ -404,13 +404,13 @@ public function it_should_get_participants_string(): void
$thread->participants()->saveMany([$participant_1, $participant_2, $participant_3]);

$string = $thread->participantsString();
$this->assertEquals('Chris Gmyr, Adam Wathan, Taylor Otwell', $string);
$this->assertSame('Chris Gmyr, Adam Wathan, Taylor Otwell', $string);

$string = $thread->participantsString(1);
$this->assertEquals('Adam Wathan, Taylor Otwell', $string);
$this->assertSame('Adam Wathan, Taylor Otwell', $string);

$string = $thread->participantsString(1, ['email']);
$this->assertEquals('[email protected], [email protected]', $string);
$this->assertSame('[email protected], [email protected]', $string);
}

/** @test */
Expand Down Expand Up @@ -440,7 +440,7 @@ public function it_should_remove_a_single_participant(): void

$thread->removeParticipant(2);

$this->assertEquals(1, $thread->participants()->count());
$this->assertSame(1, $thread->participants()->count());
}

/** @test */
Expand All @@ -455,7 +455,7 @@ public function it_should_remove_a_group_of_participants_with_array(): void

$thread->removeParticipant([1, 2]);

$this->assertEquals(0, $thread->participants()->count());
$this->assertSame(0, $thread->participants()->count());
}

/** @test */
Expand All @@ -470,7 +470,7 @@ public function it_should_remove_a_group_of_participants_with_arguments(): void

$thread->removeParticipant(1, 2);

$this->assertEquals(0, $thread->participants()->count());
$this->assertSame(0, $thread->participants()->count());
}

/** @test */
Expand Down Expand Up @@ -507,7 +507,7 @@ public function it_should_get_all_unread_messages_for_user(): void

$secondParticipantUnreadMessages = $thread->userUnreadMessages($participant_2->user_id);
$this->assertCount(1, $secondParticipantUnreadMessages);
$this->assertEquals('Message 2', $secondParticipantUnreadMessages->first()->body);
$this->assertSame('Message 2', $secondParticipantUnreadMessages->first()->body);
}

/** @test */
Expand Down Expand Up @@ -544,15 +544,15 @@ public function it_should_get_all_unread_messages_for_user_when_dates_not_set():

$secondParticipantUnreadMessages = $thread->userUnreadMessages($participant_2->user_id);
$this->assertCount(1, $secondParticipantUnreadMessages);
$this->assertEquals('Message 2', $secondParticipantUnreadMessages->first()->body);
$this->assertSame('Message 2', $secondParticipantUnreadMessages->first()->body);
}

/** @test */
public function it_should_return_empty_collection_when_user_not_participant(): void
{
$thread = $this->threadFactory();

$this->assertEquals(0, $thread->userUnreadMessagesCount(1));
$this->assertSame(0, $thread->userUnreadMessagesCount(1));
}

/** @test */
Expand All @@ -574,7 +574,7 @@ public function it_should_get_the_creator_of_a_thread(): void

$thread->messages()->saveMany([$message_1, $message_2, $message_3]);

$this->assertEquals('Chris Gmyr', $thread->creator()->name);
$this->assertSame('Chris Gmyr', $thread->creator()->name);
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/MessagableTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ public function it_should_get_all_threads_with_new_messages(): void
$thread2->messages()->saveMany([$message_1b]);

$threads = $user->threadsWithNewMessages();
$this->assertEquals(1, $threads->first()->id);
$this->assertSame(1, $threads->first()->id);

$this->assertEquals(1, $user->newThreadsCount());
$this->assertSame(1, $user->newThreadsCount());
}

/** @test */
Expand Down Expand Up @@ -59,7 +59,7 @@ public function it_get_all_incoming_messages_count_for_user(): void

$thread_2->messages()->saveMany([$this->messageFactory(['user_id' => 2])]);

$this->assertEquals(10, $user->unreadMessagesCount());
$this->assertSame(10, $user->unreadMessagesCount());
}

/** @test */
Expand Down

0 comments on commit 4eb19a0

Please sign in to comment.