Events with no date are not returned

GH-160
This commit is contained in:
Oliver Davies 2019-12-27 15:08:01 +00:00
parent 1c3d7f820f
commit 2133af2a4a
2 changed files with 28 additions and 0 deletions

View file

@ -99,6 +99,8 @@ class TalksExtension extends AbstractExtension
{ {
return (new Collection($talks))->flatMap(function ($talk): array { return (new Collection($talks))->flatMap(function ($talk): array {
return $talk['events']; return $talk['events'];
})->filter(function ($event): bool {
return !empty($event['date']);
}); });
} }
} }

View file

@ -57,4 +57,30 @@ class RetrievingEventsTest extends TestCase
$this->assertCount(2, $events); $this->assertCount(2, $events);
} }
/** @test */
public function events_with_no_date_are_not_returned()
{
$talks = [
[
'title' => 'Deploying PHP applications with Ansible, Ansible Vault and Ansistrano',
'events' => [
[
'event' => 'php_south_wales',
'date' => (new DateTime('-1 days'))->getTimestamp(),
],
[
'event' => 'drupal_edinburgh',
'date' => '',
],
],
],
];
$this->assertSame(1, $this->extension->getPastTalkCount($talks));
$pastEvents = $this->extension->getPastEvents($talks);
$this->assertCount(1, $pastEvents);
$this->assertSame('php_south_wales', $pastEvents[0]['event']);
}
} }