From 8ff960b9d6ab582dfd7c7602a7f62128408f61e1 Mon Sep 17 00:00:00 2001 From: peter279k Date: Thu, 21 Sep 2023 10:35:59 +0800 Subject: [PATCH] Improve assertions --- tests/CustomModelsTest.php | 6 ++-- tests/EloquentMessageTest.php | 2 +- tests/EloquentThreadTest.php | 66 +++++++++++++++++------------------ tests/MessagableTraitTest.php | 6 ++-- 4 files changed, 40 insertions(+), 40 deletions(-) diff --git a/tests/CustomModelsTest.php b/tests/CustomModelsTest.php index 6f1d16e..b5b7bed 100644 --- a/tests/CustomModelsTest.php +++ b/tests/CustomModelsTest.php @@ -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(); @@ -53,7 +53,7 @@ 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 */ @@ -61,7 +61,7 @@ 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(); } diff --git a/tests/EloquentMessageTest.php b/tests/EloquentMessageTest.php index f5a6411..db37d92 100644 --- a/tests/EloquentMessageTest.php +++ b/tests/EloquentMessageTest.php @@ -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()); } } diff --git a/tests/EloquentThreadTest.php b/tests/EloquentThreadTest.php index 1f7d1ab..8512785 100644 --- a/tests/EloquentThreadTest.php +++ b/tests/EloquentThreadTest.php @@ -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 */ @@ -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 */ @@ -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 */ @@ -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); } @@ -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 */ @@ -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 */ @@ -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 */ @@ -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 */ @@ -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 */ @@ -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); } } @@ -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('adam@test.com, taylor@test.com', $string); + $this->assertSame('adam@test.com, taylor@test.com', $string); } /** @test */ @@ -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 */ @@ -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 */ @@ -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 */ @@ -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 */ @@ -544,7 +544,7 @@ 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 */ @@ -552,7 +552,7 @@ public function it_should_return_empty_collection_when_user_not_participant(): v { $thread = $this->threadFactory(); - $this->assertEquals(0, $thread->userUnreadMessagesCount(1)); + $this->assertSame(0, $thread->userUnreadMessagesCount(1)); } /** @test */ @@ -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); } /** diff --git a/tests/MessagableTraitTest.php b/tests/MessagableTraitTest.php index 0edd69a..51d4e15 100644 --- a/tests/MessagableTraitTest.php +++ b/tests/MessagableTraitTest.php @@ -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 */ @@ -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 */