From df7b6315ba85ad366a7b637fcc4bba2bb7335812 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Mon, 20 May 2019 20:36:23 +0100 Subject: [PATCH] Update tests --- .../src/TwigExtension/TalksExtension.php | 5 +++ src/Talks/tests/RetrievingEventsTest.php | 44 +++---------------- src/Talks/tests/RetrievingTalksTest.php | 16 ++++--- 3 files changed, 20 insertions(+), 45 deletions(-) diff --git a/src/Talks/src/TwigExtension/TalksExtension.php b/src/Talks/src/TwigExtension/TalksExtension.php index bb485d0e..c7af7e3e 100644 --- a/src/Talks/src/TwigExtension/TalksExtension.php +++ b/src/Talks/src/TwigExtension/TalksExtension.php @@ -105,4 +105,9 @@ class TalksExtension extends AbstractExtension return $talk['events']; }); } + + public function getAllEvents($talks): array + { + return $this->eventsFromTalks($talks)->toArray(); + } } diff --git a/src/Talks/tests/RetrievingEventsTest.php b/src/Talks/tests/RetrievingEventsTest.php index 2e466e67..3feb292b 100644 --- a/src/Talks/tests/RetrievingEventsTest.php +++ b/src/Talks/tests/RetrievingEventsTest.php @@ -22,38 +22,6 @@ class RetrievingEventsTest extends TestCase $this->extension = new TalksExtension(); } - /** @test */ - public function getting_all_events() - { - $talkA = [ - 'title' => 'Talk A', - 'events' => [ - [ - 'event' => 'event_a', - 'date' => (new DateTime('-1 days'))->getTimestamp() - ], - [ - 'event' => 'event_b', - 'date' => (new DateTime('+1 days'))->getTimestamp() - ], - ], - ]; - - $talkB = [ - 'title' => 'Talk B', - 'events' => [ - [ - 'event' => 'event_a', - 'date' => (new DateTime('-3 days'))->getTimestamp() - ], - ], - ]; - - $talks = $this->extension->getTalks([$talkA, $talkB]); - $this->assertInstanceOf(Collection::class, $talks); - $this->assertCount(3, $this->extension->getEvents($talks)); - } - /** @test */ public function get_past_events() { @@ -82,12 +50,12 @@ class RetrievingEventsTest extends TestCase ]; $talks = $this->extension->getTalks([$talkA, $talkB]); - $events = $this->extension->getEvents($talks); + $events = $this->extension->filterPastEvents($talks); $this->assertInstanceOf(Collection::class, $talks); - $this->assertInstanceOf(Collection::class, $events); + $this->assertTrue(is_array($events)); - $this->assertCount(2, $this->extension->filterPastEvents($events)); + $this->assertCount(2, $events); } /** @test */ public function get_current_or_upcoming_events() @@ -118,11 +86,11 @@ class RetrievingEventsTest extends TestCase $talks = $this->extension->getTalks([$talkA, $talkB]); - $events = $this->extension->getEvents($talks); + $events = $this->extension->filterUpcomingEvents($talks); $this->assertInstanceOf(Collection::class, $talks); - $this->assertInstanceOf(Collection::class, $events); + $this->assertTrue(is_array($events)); - $this->assertCount(2, $this->extension->filterUpcomingEvents($events)); + $this->assertCount(2, $events); } } diff --git a/src/Talks/tests/RetrievingTalksTest.php b/src/Talks/tests/RetrievingTalksTest.php index 58cbdf06..24f4c8a7 100644 --- a/src/Talks/tests/RetrievingTalksTest.php +++ b/src/Talks/tests/RetrievingTalksTest.php @@ -92,10 +92,10 @@ class RetrievingTalksTest extends TestCase ]; $talks = $this->extension->getTalks([$pastTalk, $futureTalk]); - $filtered = $this->extension->filterPast($talks); + $filtered = $this->extension->filterPastTalks($talks); $this->assertCount(1, $filtered); - $this->assertSame($pastTalk, $filtered->first()); + $this->assertSame($pastTalk, $filtered[0]); } /** @test */ @@ -123,10 +123,10 @@ class RetrievingTalksTest extends TestCase ]; $talks = $this->extension->getTalks([$pastTalk, $todayTalk, $futureTalk]); - $filtered = $this->extension->filterUpcoming($talks); + $filtered = $this->extension->filterUpcomingTalks($talks); $this->assertCount(2, $filtered); - $this->assertSame([$todayTalk, $futureTalk], $filtered->toArray()); + $this->assertSame([$todayTalk, $futureTalk], $filtered); } /** @test */ @@ -142,8 +142,8 @@ class RetrievingTalksTest extends TestCase $talks = $this->extension->getTalks([$talk]); - $this->assertCount(1, $this->extension->filterUpcoming($talks)); - $this->assertEmpty($this->extension->filterPast($talks)); + $this->assertCount(1, $this->extension->filterUpcomingTalks($talks)); + $this->assertEmpty($this->extension->filterPastTalks($talks)); } /** @test */ @@ -166,7 +166,9 @@ class RetrievingTalksTest extends TestCase $talks = collect([$talkA, $talkB]); - tap($this->extension->getEvents($talks), function (Collection $events) { + tap($this->extension->getAllEvents($talks), function (array $events) { + $events = collect($events); + $this->assertCount(3, $events); $this->assertSame(