From c1606b48680df31d88ed73848447393d941a95af Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Fri, 14 Jan 2022 00:24:22 +0000 Subject: [PATCH] refactor: extract custom assertions --- tests/EventRepositoryContractTest.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/tests/EventRepositoryContractTest.php b/tests/EventRepositoryContractTest.php index a87a511..6c5405e 100644 --- a/tests/EventRepositoryContractTest.php +++ b/tests/EventRepositoryContractTest.php @@ -3,6 +3,7 @@ namespace App\Tests; use App\EventRepository; +use Tightenco\Collect\Support\Collection; trait EventRepositoryContractTest { @@ -13,7 +14,7 @@ trait EventRepositoryContractTest { $attendees = $this->repository->findAttendeesForEvent(); - $this->assertFalse($attendees->pluck('is_attending')->contains(false)); + $this->assertOnlyAttendingAttendeesAreReturned($attendees); } /** @test */ @@ -21,6 +22,16 @@ trait EventRepositoryContractTest { $attendees = $this->repository->findAttendeesForEvent(); + $this->assertEventHostsAreNotReturned($attendees); + } + + private function assertEventHostsAreNotReturned(Collection $attendees): void + { $this->assertSame([false], $attendees->pluck('is_host')->unique()->toArray()); } + + private function assertOnlyAttendingAttendeesAreReturned(Collection $attendees): void + { + $this->assertFalse($attendees->pluck('is_attending')->contains(false)); + } }