Skip to content

Commit 2966fcc

Browse files
authored
Improve assertions (#398)
1 parent 1ae9999 commit 2966fcc

File tree

4 files changed

+40
-40
lines changed

4 files changed

+40
-40
lines changed

tests/CustomModelsTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function it_can_use_custom_table(): void
4242
$this->setMessageCustomModel();
4343
$this->setMessageCustomTable();
4444

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

4747
$this->unsetMessageCustomModel();
4848
$this->unsetMessageCustomTable();
@@ -53,15 +53,15 @@ public function it_should_return_custom_name_when_not_available(): void
5353
{
5454
$modelName = 'ModelNotFound';
5555

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

5959
/** :TODO: test */
6060
public function it_can_get_custom_model_table_property(): void
6161
{
6262
$this->setMessageCustomModel();
6363

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

6666
$this->unsetMessageCustomModel();
6767
}

tests/EloquentMessageTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,6 @@ public function it_should_get_the_recipients_of_a_message(): void
1818

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

21-
$this->assertEquals(2, $message->recipients()->count());
21+
$this->assertSame(2, $message->recipients()->count());
2222
}
2323
}

tests/EloquentThreadTest.php

+33-33
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ public function search_specific_thread_by_subject(): void
3939

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

42-
$this->assertEquals(1, $threads->count());
43-
$this->assertEquals(1, $threads->first()->id);
44-
$this->assertEquals('first subject', $threads->first()->subject);
42+
$this->assertSame(1, $threads->count());
43+
$this->assertSame(1, $threads->first()->id);
44+
$this->assertSame('first subject', $threads->first()->subject);
4545
}
4646

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

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

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

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

60-
$this->assertEquals(2, $threads->last()->id);
61-
$this->assertEquals('second subject', $threads->last()->subject);
60+
$this->assertSame(2, $threads->last()->id);
61+
$this->assertSame('second subject', $threads->last()->subject);
6262
}
6363

6464
/** @test */
6565
public function it_should_create_a_new_thread(): void
6666
{
6767
$thread = $this->threadFactory();
68-
$this->assertEquals('Sample thread', $thread->subject);
68+
$this->assertSame('Sample thread', $thread->subject);
6969

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

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

8686
$thread = $this->threadFactory();
8787
$thread->messages()->saveMany([$oldMessage, $newMessage]);
88-
$this->assertEquals($newMessage->body, $thread->latestMessage->body);
88+
$this->assertSame($newMessage->body, $thread->latestMessage->body);
8989
}
9090

9191
/** @test */
@@ -117,11 +117,11 @@ public function it_should_get_all_thread_participants(): void
117117

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

122122
$participantIds = $thread->participantsUserIds(999);
123123
$this->assertCount(4, $participantIds);
124-
$this->assertEquals(999, end($participantIds));
124+
$this->assertSame(999, end($participantIds));
125125

126126
$this->assertIsArray($participantIds);
127127
}
@@ -254,7 +254,7 @@ public function it_should_add_a_participant_to_a_thread(): void
254254

255255
$thread->addParticipant($participant);
256256

257-
$this->assertEquals(1, $thread->participants()->count());
257+
$this->assertSame(1, $thread->participants()->count());
258258
}
259259

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

267267
$thread->addParticipant($participants);
268268

269-
$this->assertEquals(3, $thread->participants()->count());
269+
$this->assertSame(3, $thread->participants()->count());
270270
}
271271

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

277277
$thread->addParticipant(1, 2);
278278

279-
$this->assertEquals(2, $thread->participants()->count());
279+
$this->assertSame(2, $thread->participants()->count());
280280
}
281281

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

292292
$thread->markAsRead($userId);
293293

294-
$this->assertNotEquals($thread->getParticipantFromUser($userId)->last_read, $last_read);
294+
$this->assertNotSame($thread->getParticipantFromUser($userId)->last_read, $last_read);
295295
}
296296

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

357357
$participants = $thread->participants();
358-
$this->assertEquals(0, $participants->count());
358+
$this->assertSame(0, $participants->count());
359359

360360
$thread->activateAllParticipants();
361361

362362
$participants = $thread->participants();
363-
$this->assertEquals(3, $participants->count());
363+
$this->assertSame(3, $participants->count());
364364
}
365365

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

377377
if (config('database.connections.testbench.driver') === 'mysql') {
378-
$this->assertEquals('concat' . $expectedString, $select);
378+
$this->assertSame('concat' . $expectedString, $select);
379379
} else {
380-
$this->assertEquals($expectedString, $select);
380+
$this->assertSame($expectedString, $select);
381381
}
382382

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

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

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

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

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

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

416416
/** @test */
@@ -440,7 +440,7 @@ public function it_should_remove_a_single_participant(): void
440440

441441
$thread->removeParticipant(2);
442442

443-
$this->assertEquals(1, $thread->participants()->count());
443+
$this->assertSame(1, $thread->participants()->count());
444444
}
445445

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

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

458-
$this->assertEquals(0, $thread->participants()->count());
458+
$this->assertSame(0, $thread->participants()->count());
459459
}
460460

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

471471
$thread->removeParticipant(1, 2);
472472

473-
$this->assertEquals(0, $thread->participants()->count());
473+
$this->assertSame(0, $thread->participants()->count());
474474
}
475475

476476
/** @test */
@@ -507,7 +507,7 @@ public function it_should_get_all_unread_messages_for_user(): void
507507

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

513513
/** @test */
@@ -544,15 +544,15 @@ public function it_should_get_all_unread_messages_for_user_when_dates_not_set():
544544

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

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

555-
$this->assertEquals(0, $thread->userUnreadMessagesCount(1));
555+
$this->assertSame(0, $thread->userUnreadMessagesCount(1));
556556
}
557557

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

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

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

580580
/**

tests/MessagableTraitTest.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ public function it_should_get_all_threads_with_new_messages(): void
2929
$thread2->messages()->saveMany([$message_1b]);
3030

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

34-
$this->assertEquals(1, $user->newThreadsCount());
34+
$this->assertSame(1, $user->newThreadsCount());
3535
}
3636

3737
/** @test */
@@ -59,7 +59,7 @@ public function it_get_all_incoming_messages_count_for_user(): void
5959

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

62-
$this->assertEquals(10, $user->unreadMessagesCount());
62+
$this->assertSame(10, $user->unreadMessagesCount());
6363
}
6464

6565
/** @test */

0 commit comments

Comments
 (0)