Add OpdaviesTwigExtensionTest
This commit is contained in:
parent
6888675252
commit
6ee3e91363
5 changed files with 1732 additions and 3 deletions
78
tests/Opdavies/TwigExtension/OpdaviesTwigExtensionTest.php
Normal file
78
tests/Opdavies/TwigExtension/OpdaviesTwigExtensionTest.php
Normal file
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
namespace App\Tests\Opdavies\TwigExtension;
|
||||
|
||||
use App\Opdavies\TwigExtension\OpdaviesTwigExtension;
|
||||
use Dflydev\DotAccessConfiguration\Configuration;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Sculpin\Contrib\ProxySourceCollection\ProxySourceItem;
|
||||
|
||||
class OpdaviesTwigExtensionTest extends TestCase
|
||||
{
|
||||
private OpdaviesTwigExtension $extension;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
$this->extension = new OpdaviesTwigExtension();
|
||||
}
|
||||
|
||||
public function testNoPastEvents(): void
|
||||
{
|
||||
$talk = $this->createTalk(
|
||||
events: [
|
||||
['date' => (new \DateTime('+1 days'))->getTimestamp()],
|
||||
],
|
||||
);
|
||||
|
||||
self::assertSame(0, $this->extension->getPastTalkCount([$talk]));
|
||||
}
|
||||
|
||||
public function testSinglePastEvent(): void
|
||||
{
|
||||
$talkA = $this->createTalk(
|
||||
events: [
|
||||
['date' => (new \DateTime('+1 days'))->getTimestamp()],
|
||||
],
|
||||
);
|
||||
|
||||
$talkB = $this->createTalk(
|
||||
events: [
|
||||
['date' => (new \DateTime('-3 days'))->getTimestamp()],
|
||||
],
|
||||
);
|
||||
|
||||
self::assertSame(1, $this->extension->getPastTalkCount([$talkA, $talkB]));
|
||||
}
|
||||
|
||||
public function testMultiplePastEvents(): void
|
||||
{
|
||||
$talkA = $this->createTalk(
|
||||
events: [
|
||||
['date' => (new \DateTime('-1 days'))->getTimestamp()],
|
||||
['date' => (new \DateTime('+1 days'))->getTimestamp()],
|
||||
],
|
||||
);
|
||||
|
||||
$talkB = $this->createTalk(
|
||||
events: [
|
||||
['date' => (new \DateTime('-3 days'))->getTimestamp()],
|
||||
],
|
||||
);
|
||||
|
||||
self::assertSame(2, $this->extension->getPastTalkCount([$talkA, $talkB]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a mock talk with a list of events.
|
||||
*/
|
||||
private function createTalk(array $events): ProxySourceItem
|
||||
{
|
||||
$configuration = $this->createMock(Configuration::class);
|
||||
$configuration->method('get')->with($this->identicalTo('events'))->willReturn($events);
|
||||
|
||||
$talk = $this->createMock(ProxySourceItem::class);
|
||||
$talk->method('data')->willReturn($configuration);
|
||||
|
||||
return $talk;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue