feat(meetup): add Meetup implementation
This commit is contained in:
parent
f3eda70384
commit
5ab4097ace
|
@ -26,5 +26,5 @@ services:
|
|||
# add more service definitions when explicit configuration is needed
|
||||
# please note that last definitions always *replace* previous ones
|
||||
App\EventRepository:
|
||||
class: App\Tests\FakeEventRepository
|
||||
class: App\MeetupEventRepository
|
||||
public: true
|
||||
|
|
35
src/MeetupEventRepository.php
Normal file
35
src/MeetupEventRepository.php
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Symfony\Contracts\HttpClient\HttpClientInterface;
|
||||
use Tightenco\Collect\Support\Collection;
|
||||
|
||||
final class MeetupEventRepository implements EventRepository
|
||||
{
|
||||
private HttpClientInterface $client;
|
||||
|
||||
public function __construct(
|
||||
HttpClientInterface $client
|
||||
) {
|
||||
$this->client = $client;
|
||||
}
|
||||
|
||||
public function getConfirmedAttendees(): Collection
|
||||
{
|
||||
$response = $this->client->request('GET', 'https://api.meetup.com/php-south-wales/events/282265786/rsvps');
|
||||
|
||||
$rsvps = json_decode($response->getContent());
|
||||
|
||||
return Collection::make($rsvps)
|
||||
->filter(fn (\stdClass $rsvp): bool => $rsvp->response == 'yes')
|
||||
->filter(fn (\stdClass $attendee): bool => !$attendee->member->event_context->host)
|
||||
->map(function (\stdClass $attendee): \stdClass {
|
||||
$attendee->is_attending = true;
|
||||
$attendee->is_host = false;
|
||||
|
||||
return $attendee;
|
||||
})
|
||||
;
|
||||
}
|
||||
}
|
|
@ -21,6 +21,6 @@ trait EventRepositoryContractTest
|
|||
{
|
||||
$attendees = $this->repository->getConfirmedAttendees();
|
||||
|
||||
$this->assertFalse($attendees->pluck('is_host')->contains(true));
|
||||
$this->assertSame([false], $attendees->pluck('is_host')->unique()->toArray());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -9,19 +9,24 @@ use Tightenco\Collect\Support\Collection;
|
|||
|
||||
final class FakeEventRepository implements EventRepository
|
||||
{
|
||||
private static array $rsvps = [
|
||||
['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],
|
||||
private static array $rsvps = [];
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
self::$rsvps = [
|
||||
(object) ['name' => 'Oliver Davies.', 'is_attending' => true, 'is_host' => true],
|
||||
(object) ['name' => 'matthew s.', 'is_attending' => true, 'is_host' => false],
|
||||
(object) ['name' => 'Michael P.', 'is_attending' => true, 'is_host' => false],
|
||||
(object) ['name' => 'Kathryn "Kat" R.', 'is_attending' => true, 'is_host' => false],
|
||||
(object) ['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['is_attending'])
|
||||
->filter(fn (array $attendee): bool => !$attendee['is_host'])
|
||||
->filter(fn (\stdClass $attendee): bool => $attendee->is_attending)
|
||||
->filter(fn (\stdClass $attendee): bool => !$attendee->is_host)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,10 @@ final class FakeEventRepositoryTest extends KernelTestCase
|
|||
{
|
||||
self::bootKernel();
|
||||
|
||||
$container = static::$container;
|
||||
|
||||
$container->set(EventRepository::class, new FakeEventRepository());
|
||||
|
||||
$this->repository = static::$container->get(EventRepository::class);
|
||||
}
|
||||
}
|
||||
|
|
23
tests/MeetupEventRepositoryTest.php
Normal file
23
tests/MeetupEventRepositoryTest.php
Normal file
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace App\Tests;
|
||||
|
||||
use App\EventRepository;
|
||||
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
|
||||
|
||||
/**
|
||||
* @group api
|
||||
*/
|
||||
final class MeetupEventRepositoryTest extends KernelTestCase
|
||||
{
|
||||
use EventRepositoryContractTest;
|
||||
|
||||
private EventRepository $repository;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
self::bootKernel();
|
||||
|
||||
$this->repository = self::$container->get(EventRepository::class);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue