refactor: generalise logic in the fake repository
This commit is contained in:
parent
ae38fbf2b9
commit
f3eda70384
|
@ -1,11 +0,0 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App;
|
||||
|
||||
final class RsvpResponse
|
||||
{
|
||||
public const RESPONSE_NO = 'no';
|
||||
public const RESPONSE_YES = 'yes';
|
||||
}
|
|
@ -13,7 +13,7 @@ trait EventRepositoryContractTest
|
|||
{
|
||||
$attendees = $this->repository->getConfirmedAttendees();
|
||||
|
||||
$this->assertCount(3, $attendees);
|
||||
$this->assertFalse($attendees->pluck('is_attending')->contains(false));
|
||||
}
|
||||
|
||||
/** @test */
|
||||
|
@ -21,6 +21,6 @@ trait EventRepositoryContractTest
|
|||
{
|
||||
$attendees = $this->repository->getConfirmedAttendees();
|
||||
|
||||
$this->assertCount(3, $attendees);
|
||||
$this->assertFalse($attendees->pluck('is_host')->contains(true));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,24 +5,22 @@ declare(strict_types=1);
|
|||
namespace App\Tests;
|
||||
|
||||
use App\EventRepository;
|
||||
use App\RsvpResponse;
|
||||
use Tightenco\Collect\Support\Collection;
|
||||
|
||||
final class FakeEventRepository implements EventRepository
|
||||
{
|
||||
private static array $rsvps = [
|
||||
['name' => 'Oliver Davies.', 'response' => RsvpResponse::RESPONSE_YES, 'is_host' => true],
|
||||
['name' => 'matthew s.', 'response' => RsvpResponse::RESPONSE_YES, 'is_host' => false],
|
||||
['name' => 'Michael P.', 'response' => RsvpResponse::RESPONSE_YES, 'is_host' => false],
|
||||
['name' => 'Kathryn "Kat" R.', 'response' => RsvpResponse::RESPONSE_YES, 'is_host' => false],
|
||||
['name' => 'Did not attend', 'response' => RsvpResponse::RESPONSE_NO, 'is_host' => false],
|
||||
['name' => 'Oliver Davies.', 'is_attending' => true, 'is_host' => true],
|
||||
['name' => 'matthew s.', 'is_attending' => true, 'is_host' => false],
|
||||
['name' => 'Michael P.', 'is_attending' => true, 'is_host' => false],
|
||||
['name' => 'Kathryn "Kat" R.', 'is_attending' => true, 'is_host' => false],
|
||||
['name' => 'Did not attend', 'is_attending' => false, 'is_host' => false],
|
||||
];
|
||||
|
||||
public function getConfirmedAttendees(): Collection
|
||||
{
|
||||
return Collection::make(self::$rsvps)
|
||||
->filter(fn (array $attendee): bool => $attendee['response']
|
||||
== RsvpResponse::RESPONSE_YES)
|
||||
->filter(fn (array $attendee): bool => $attendee['is_attending'])
|
||||
->filter(fn (array $attendee): bool => !$attendee['is_host'])
|
||||
;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue