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();
|
$attendees = $this->repository->getConfirmedAttendees();
|
||||||
|
|
||||||
$this->assertCount(3, $attendees);
|
$this->assertFalse($attendees->pluck('is_attending')->contains(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** @test */
|
/** @test */
|
||||||
|
@ -21,6 +21,6 @@ trait EventRepositoryContractTest
|
||||||
{
|
{
|
||||||
$attendees = $this->repository->getConfirmedAttendees();
|
$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;
|
namespace App\Tests;
|
||||||
|
|
||||||
use App\EventRepository;
|
use App\EventRepository;
|
||||||
use App\RsvpResponse;
|
|
||||||
use Tightenco\Collect\Support\Collection;
|
use Tightenco\Collect\Support\Collection;
|
||||||
|
|
||||||
final class FakeEventRepository implements EventRepository
|
final class FakeEventRepository implements EventRepository
|
||||||
{
|
{
|
||||||
private static array $rsvps = [
|
private static array $rsvps = [
|
||||||
['name' => 'Oliver Davies.', 'response' => RsvpResponse::RESPONSE_YES, 'is_host' => true],
|
['name' => 'Oliver Davies.', 'is_attending' => true, 'is_host' => true],
|
||||||
['name' => 'matthew s.', 'response' => RsvpResponse::RESPONSE_YES, 'is_host' => false],
|
['name' => 'matthew s.', 'is_attending' => true, 'is_host' => false],
|
||||||
['name' => 'Michael P.', 'response' => RsvpResponse::RESPONSE_YES, 'is_host' => false],
|
['name' => 'Michael P.', 'is_attending' => true, 'is_host' => false],
|
||||||
['name' => 'Kathryn "Kat" R.', 'response' => RsvpResponse::RESPONSE_YES, 'is_host' => false],
|
['name' => 'Kathryn "Kat" R.', 'is_attending' => true, 'is_host' => false],
|
||||||
['name' => 'Did not attend', 'response' => RsvpResponse::RESPONSE_NO, 'is_host' => false],
|
['name' => 'Did not attend', 'is_attending' => false, 'is_host' => false],
|
||||||
];
|
];
|
||||||
|
|
||||||
public function getConfirmedAttendees(): Collection
|
public function getConfirmedAttendees(): Collection
|
||||||
{
|
{
|
||||||
return Collection::make(self::$rsvps)
|
return Collection::make(self::$rsvps)
|
||||||
->filter(fn (array $attendee): bool => $attendee['response']
|
->filter(fn (array $attendee): bool => $attendee['is_attending'])
|
||||||
== RsvpResponse::RESPONSE_YES)
|
|
||||||
->filter(fn (array $attendee): bool => !$attendee['is_host'])
|
->filter(fn (array $attendee): bool => !$attendee['is_host'])
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue