Add OpdaviesTwigExtensionTest
This commit is contained in:
parent
6888675252
commit
6ee3e91363
4
.gitignore
vendored
4
.gitignore
vendored
|
@ -7,3 +7,7 @@
|
||||||
|
|
||||||
/node_modules/
|
/node_modules/
|
||||||
/source/build/
|
/source/build/
|
||||||
|
|
||||||
|
# PHPUnit.
|
||||||
|
/.phpunit.cache/
|
||||||
|
/.phpunit.result.cache
|
||||||
|
|
|
@ -12,5 +12,12 @@
|
||||||
"autoload": {
|
"autoload": {
|
||||||
"psr-4": {
|
"psr-4": {
|
||||||
"App\\": "src" }
|
"App\\": "src" }
|
||||||
}
|
},
|
||||||
|
"autoload-dev": {
|
||||||
|
"psr-4": {
|
||||||
|
"App\\Tests\\": "tests" }
|
||||||
|
},
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "^11.1"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
1636
composer.lock
generated
1636
composer.lock
generated
File diff suppressed because it is too large
Load diff
8
phpunit.xml.dist
Normal file
8
phpunit.xml.dist
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="./vendor/autoload.php" colors="true" stopOnFailure="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.1/phpunit.xsd" cacheDirectory=".phpunit.cache">
|
||||||
|
<testsuites>
|
||||||
|
<testsuite name="unit tests">
|
||||||
|
<directory suffix="Test.php">tests</directory>
|
||||||
|
</testsuite>
|
||||||
|
</testsuites>
|
||||||
|
</phpunit>
|
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…
Reference in a new issue