oliverdavies.uk/tests/TalkExtensionTest.php

135 lines
3.5 KiB
PHP
Raw Normal View History

<?php
namespace App\Tests;
use App\TwigExtension\TalkExtension;
2021-08-25 09:48:56 +00:00
use Carbon\Carbon;
use PHPUnit\Framework\TestCase;
final class TalkExtensionTest extends TestCase
{
2021-08-25 00:11:57 +00:00
private TalkExtension $subject;
public function setUp(): void
{
$this->subject = new TalkExtension();
}
/** @test */
2021-09-08 22:36:38 +00:00
public function should_return_zero_if_there_are_no_talks(): void
{
2021-08-25 00:30:52 +00:00
$this->assertSame(0, $this->subject->getPastTalkCount());
2021-08-25 00:11:57 +00:00
}
/** @test */
2021-09-08 22:36:38 +00:00
public function should_count_a_single_event_from_a_single_talk(): void
2021-08-25 00:11:57 +00:00
{
$talks = [
[
'title' => 'Building static sites with Sculpin',
'events' => [
[
'date' => Carbon::today()->subDay()->format('Y-m-d'),
],
2021-08-25 00:11:57 +00:00
]
],
];
$this->assertSame(1, $this->subject->getPastTalkCount($talks));
}
/** @test */
2021-09-08 22:36:38 +00:00
public function should_count_multiple_events_from_a_single_talk(): void
2021-08-25 00:11:57 +00:00
{
2021-08-25 08:00:00 +00:00
$talks = [
[
'title' => 'Building static sites with Sculpin',
'events' => [
[
'date' => Carbon::today()->subDay()->format('Y-m-d'),
],
[
'date' => Carbon::today()->subDay()->format('Y-m-d'),
],
2021-08-25 08:00:00 +00:00
]
],
];
$this->assertSame(2, $this->subject->getPastTalkCount($talks));
2021-08-25 00:11:57 +00:00
}
/** @test */
2021-09-08 22:36:38 +00:00
public function should_count_multiple_events_from_multiple_talks(): void
2021-08-25 00:11:57 +00:00
{
2021-08-25 08:00:00 +00:00
$talks = [
[
'title' => 'Building static sites with Sculpin',
'events' => [
[
'date' => Carbon::today()->subDay()->format('Y-m-d'),
],
2021-08-25 08:00:00 +00:00
]
],
[
'title' => 'TDD - Test Driven Drupal',
'events' => [
[
'date' => Carbon::today()->subDay()->format('Y-m-d'),
],
2021-08-25 08:00:00 +00:00
]
],
];
$this->assertSame(2, $this->subject->getPastTalkCount($talks));
2021-08-25 00:11:57 +00:00
}
/** @test */
2021-09-08 22:36:38 +00:00
public function should_exclude_future_talks(): void
2021-08-25 00:11:57 +00:00
{
2021-08-25 09:48:56 +00:00
$talks = [
[
'title' => 'Building static sites with Sculpin',
'events' => [
[
'date' => Carbon::today()->subDay()->format('Y-m-d'),
2021-08-25 09:48:56 +00:00
],
],
],
[
'title' => 'TDD - Test Driven Drupal',
'events' => [
[
'date' => Carbon::today()->addDay()->format('Y-m-d'),
2021-08-25 09:48:56 +00:00
],
],
],
];
$this->assertSame(1, $this->subject->getPastTalkCount($talks));
}
/** @test */
public function should_get_the_last_event_date_for_a_talk(): void
{
2021-09-13 17:00:00 +00:00
$talk = [
'events' => [
['date' => '2015-10-14'],
['date' => '2021-09-07'],
['date' => '2021-08-19'],
],
];
2021-09-13 17:00:00 +00:00
$this->assertSame('2021-09-07', $this->subject->getLastEventDate($talk));
}
/** @test */
public function should_return_null_for_the_latest_date_if_a_talk_has_no_events(): void
{
$talk = [
'events' => [],
];
2021-09-13 17:00:00 +00:00
$this->assertNull($this->subject->getLastEventDate($talk));
}
}