From 52f909da6d1b49f46364e3f4442f7af92bc5a402 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Thu, 23 May 2019 01:05:29 +0100 Subject: [PATCH] Add Schedule bundle --- app/SculpinKernel.php | 2 + composer.json | 3 +- .../SculpinScheduleExtension.php | 17 +++++++++ src/Schedule/src/Model/Session.php | 30 +++++++++++++++ src/Schedule/src/SculpinScheduleBundle.php | 9 +++++ .../src/TwigExtension/ScheduleExtension.php | 29 ++++++++++++++ src/Schedule/tests/ScheduleTest.php | 38 +++++++++++++++++++ 7 files changed, 127 insertions(+), 1 deletion(-) create mode 100644 src/Schedule/src/DependencyInjection/SculpinScheduleExtension.php create mode 100644 src/Schedule/src/Model/Session.php create mode 100644 src/Schedule/src/SculpinScheduleBundle.php create mode 100644 src/Schedule/src/TwigExtension/ScheduleExtension.php create mode 100644 src/Schedule/tests/ScheduleTest.php diff --git a/app/SculpinKernel.php b/app/SculpinKernel.php index 250870c..090ba84 100644 --- a/app/SculpinKernel.php +++ b/app/SculpinKernel.php @@ -1,5 +1,6 @@ load('services.yml'); + } +} diff --git a/src/Schedule/src/Model/Session.php b/src/Schedule/src/Model/Session.php new file mode 100644 index 0000000..ecce4d1 --- /dev/null +++ b/src/Schedule/src/Model/Session.php @@ -0,0 +1,30 @@ +data = $data; + } + + public function getSlot(): int + { + return (int) $this->data['slot']; + } + + public function getTitle(): string + { + return $this->data['title']; + } + + public function getSpeakers(): Collection + { + return collect($this->data['speakers']); + } +} diff --git a/src/Schedule/src/SculpinScheduleBundle.php b/src/Schedule/src/SculpinScheduleBundle.php new file mode 100644 index 0000000..d3c7aae --- /dev/null +++ b/src/Schedule/src/SculpinScheduleBundle.php @@ -0,0 +1,9 @@ +map(function ($session): ?Session { + return new Session($session); + })->first(function (?Session $session) use ($slotId): bool { + return $session->getSlot() == $slotId; + }); + } +} diff --git a/src/Schedule/tests/ScheduleTest.php b/src/Schedule/tests/ScheduleTest.php new file mode 100644 index 0000000..3cda432 --- /dev/null +++ b/src/Schedule/tests/ScheduleTest.php @@ -0,0 +1,38 @@ +extension = new ScheduleExtension(); + } + + /** @test */ + public function get_a_session_for_a_slot() + { + $sessions = [ + ['title' => 'The Real State of Drupal', 'slot' => 4], + ['title' => 'Using Ansible for automation', 'slot' => 1], + ['title' => 'Introduction to Views', 'slot' => 3], + ['title' => 'Doing Good with Drupal', 'slot' => 2], + ]; + + $session = $this->extension->getSessionInSlot(3, $sessions); + + $this->assertInstanceOf(Session::class, $session); + $this->assertSame('Introduction to Views', $session->getTitle()); + } +} \ No newline at end of file