Get all events
This commit is contained in:
parent
f6e0272469
commit
679da826b4
|
@ -30,13 +30,13 @@ class TalksExtension extends AbstractExtension
|
|||
{
|
||||
return [
|
||||
new TwigFunction('getTalks', [$this, 'getTalks']),
|
||||
new TwigFunction('getEvents', [$this, 'getEvents']),
|
||||
];
|
||||
}
|
||||
|
||||
public function getFilters()
|
||||
{
|
||||
return [
|
||||
new TwigFilter('events', [$this, 'getEvents']),
|
||||
new TwigFilter('past', [$this, 'filterPast']),
|
||||
new TwigFilter('upcoming', [$this, 'filterUpcoming']),
|
||||
];
|
||||
|
@ -65,9 +65,9 @@ class TalksExtension extends AbstractExtension
|
|||
}
|
||||
|
||||
|
||||
public function getEvents(Collection $talks): Collection
|
||||
public function getEvents($talks): Collection
|
||||
{
|
||||
return $talks->flatMap(function ($talk): array {
|
||||
return collect($talks)->flatMap(function ($talk): array {
|
||||
return $talk['events'];
|
||||
});
|
||||
}
|
||||
|
|
54
src/Talks/tests/RetrievingEventsTest.php
Normal file
54
src/Talks/tests/RetrievingEventsTest.php
Normal file
|
@ -0,0 +1,54 @@
|
|||
<?php
|
||||
|
||||
namespace App\Tests\Talks;
|
||||
|
||||
use App\Talks\TwigExtension\TalksExtension;
|
||||
use DateTime;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Tightenco\Collect\Support\Collection;
|
||||
|
||||
class RetrievingEventsTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @var TalksExtension
|
||||
*/
|
||||
private $extension;
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function setUp()
|
||||
{
|
||||
$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()
|
||||
],
|
||||
],
|
||||
];
|
||||
|
||||
$this->assertCount(3, $this->extension->getEvents([$talkA, $talkB]));
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue