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