Exclude future talks from the count

This commit is contained in:
Oliver Davies 2021-08-25 10:48:56 +01:00
parent 52565c99f1
commit 6c10410a20
4 changed files with 299 additions and 8 deletions

View file

@ -11,6 +11,7 @@
],
"require": {
"illuminate/collections": "^8.55",
"nesbot/carbon": "^2.52",
"opdavies/sculpin-gist-embed-bundle": "^0.1.0",
"opdavies/sculpin-twig-markdown-bundle": "^0.2.0",
"sculpin/sculpin": "^3.0"

263
composer.lock generated
View file

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically"
],
"content-hash": "6a28aeb196f762f5be86334649e78206",
"content-hash": "e16352573256967e1714ff2adc994bbf",
"packages": [
{
"name": "dflydev/ant-path-matcher",
@ -704,6 +704,100 @@
},
"time": "2019-12-02T02:32:27+00:00"
},
{
"name": "nesbot/carbon",
"version": "2.52.0",
"source": {
"type": "git",
"url": "https://github.com/briannesbitt/Carbon.git",
"reference": "369c0e2737c56a0f39c946dd261855255a6fccbe"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/briannesbitt/Carbon/zipball/369c0e2737c56a0f39c946dd261855255a6fccbe",
"reference": "369c0e2737c56a0f39c946dd261855255a6fccbe",
"shasum": ""
},
"require": {
"ext-json": "*",
"php": "^7.1.8 || ^8.0",
"symfony/polyfill-mbstring": "^1.0",
"symfony/polyfill-php80": "^1.16",
"symfony/translation": "^3.4 || ^4.0 || ^5.0"
},
"require-dev": {
"doctrine/orm": "^2.7",
"friendsofphp/php-cs-fixer": "^2.14 || ^3.0",
"kylekatarnls/multi-tester": "^2.0",
"phpmd/phpmd": "^2.9",
"phpstan/extension-installer": "^1.0",
"phpstan/phpstan": "^0.12.54",
"phpunit/phpunit": "^7.5.20 || ^8.5.14",
"squizlabs/php_codesniffer": "^3.4"
},
"bin": [
"bin/carbon"
],
"type": "library",
"extra": {
"branch-alias": {
"dev-3.x": "3.x-dev",
"dev-master": "2.x-dev"
},
"laravel": {
"providers": [
"Carbon\\Laravel\\ServiceProvider"
]
},
"phpstan": {
"includes": [
"extension.neon"
]
}
},
"autoload": {
"psr-4": {
"Carbon\\": "src/Carbon/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Brian Nesbitt",
"email": "brian@nesbot.com",
"homepage": "https://markido.com"
},
{
"name": "kylekatarnls",
"homepage": "https://github.com/kylekatarnls"
}
],
"description": "An API extension for DateTime that supports 281 different languages.",
"homepage": "https://carbon.nesbot.com",
"keywords": [
"date",
"datetime",
"time"
],
"support": {
"issues": "https://github.com/briannesbitt/Carbon/issues",
"source": "https://github.com/briannesbitt/Carbon"
},
"funding": [
{
"url": "https://opencollective.com/Carbon",
"type": "open_collective"
},
{
"url": "https://tidelift.com/funding/github/packagist/nesbot/carbon",
"type": "tidelift"
}
],
"time": "2021-08-14T19:10:52+00:00"
},
{
"name": "netcarver/textile",
"version": "v3.7.6",
@ -3343,6 +3437,173 @@
],
"time": "2021-04-01T10:43:52+00:00"
},
{
"name": "symfony/translation",
"version": "v4.4.27",
"source": {
"type": "git",
"url": "https://github.com/symfony/translation.git",
"reference": "2e3c0f2bf704d635ba862e7198d72331a62d82ba"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/translation/zipball/2e3c0f2bf704d635ba862e7198d72331a62d82ba",
"reference": "2e3c0f2bf704d635ba862e7198d72331a62d82ba",
"shasum": ""
},
"require": {
"php": ">=7.1.3",
"symfony/polyfill-mbstring": "~1.0",
"symfony/polyfill-php80": "^1.16",
"symfony/translation-contracts": "^1.1.6|^2"
},
"conflict": {
"symfony/config": "<3.4",
"symfony/dependency-injection": "<3.4",
"symfony/http-kernel": "<4.4",
"symfony/yaml": "<3.4"
},
"provide": {
"symfony/translation-implementation": "1.0|2.0"
},
"require-dev": {
"psr/log": "^1|^2|^3",
"symfony/config": "^3.4|^4.0|^5.0",
"symfony/console": "^3.4|^4.0|^5.0",
"symfony/dependency-injection": "^3.4|^4.0|^5.0",
"symfony/finder": "~2.8|~3.0|~4.0|^5.0",
"symfony/http-kernel": "^4.4",
"symfony/intl": "^3.4|^4.0|^5.0",
"symfony/service-contracts": "^1.1.2|^2",
"symfony/yaml": "^3.4|^4.0|^5.0"
},
"suggest": {
"psr/log-implementation": "To use logging capability in translator",
"symfony/config": "",
"symfony/yaml": ""
},
"type": "library",
"autoload": {
"psr-4": {
"Symfony\\Component\\Translation\\": ""
},
"exclude-from-classmap": [
"/Tests/"
]
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Fabien Potencier",
"email": "fabien@symfony.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Provides tools to internationalize your application",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/translation/tree/v4.4.27"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2021-07-21T13:12:00+00:00"
},
{
"name": "symfony/translation-contracts",
"version": "v2.4.0",
"source": {
"type": "git",
"url": "https://github.com/symfony/translation-contracts.git",
"reference": "95c812666f3e91db75385749fe219c5e494c7f95"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/translation-contracts/zipball/95c812666f3e91db75385749fe219c5e494c7f95",
"reference": "95c812666f3e91db75385749fe219c5e494c7f95",
"shasum": ""
},
"require": {
"php": ">=7.2.5"
},
"suggest": {
"symfony/translation-implementation": ""
},
"type": "library",
"extra": {
"branch-alias": {
"dev-main": "2.4-dev"
},
"thanks": {
"name": "symfony/contracts",
"url": "https://github.com/symfony/contracts"
}
},
"autoload": {
"psr-4": {
"Symfony\\Contracts\\Translation\\": ""
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Nicolas Grekas",
"email": "p@tchwork.com"
},
{
"name": "Symfony Community",
"homepage": "https://symfony.com/contributors"
}
],
"description": "Generic abstractions related to translation",
"homepage": "https://symfony.com",
"keywords": [
"abstractions",
"contracts",
"decoupling",
"interfaces",
"interoperability",
"standards"
],
"support": {
"source": "https://github.com/symfony/translation-contracts/tree/v2.4.0"
},
"funding": [
{
"url": "https://symfony.com/sponsor",
"type": "custom"
},
{
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2021-03-23T23:28:01+00:00"
},
{
"name": "symfony/var-dumper",
"version": "v5.3.0",

View file

@ -4,6 +4,7 @@ declare(strict_types=1);
namespace App\TwigExtension;
use Carbon\Carbon;
use Illuminate\Support\Collection;
use Twig\Extension\AbstractExtension;
use Twig\TwigFunction;
@ -26,7 +27,11 @@ final class TalkExtension extends AbstractExtension
{
$talkCollection = new Collection($talks);
$today = Carbon::today()->format('Y-m-d');
return $talkCollection
->flatMap(fn($talk): array => (array) $talk['events']);
->flatMap(fn($talk): array => (array) $talk['events'])
->filter(fn(array $event): bool => $event['date'] < $today);
}
}

View file

@ -3,6 +3,7 @@
namespace App\Tests;
use App\TwigExtension\TalkExtension;
use Carbon\Carbon;
use PHPUnit\Framework\TestCase;
final class TalkExtensionTest extends TestCase
@ -27,7 +28,7 @@ final class TalkExtensionTest extends TestCase
[
'title' => 'Building static sites with Sculpin',
'events' => [
'',
['date' => Carbon::today()->subDay()->format('Y-m-d')],
]
],
];
@ -42,8 +43,8 @@ final class TalkExtensionTest extends TestCase
[
'title' => 'Building static sites with Sculpin',
'events' => [
'',
'',
['date' => Carbon::today()->subDay()->format('Y-m-d')],
['date' => Carbon::today()->subDay()->format('Y-m-d')],
]
],
];
@ -58,13 +59,13 @@ final class TalkExtensionTest extends TestCase
[
'title' => 'Building static sites with Sculpin',
'events' => [
'',
['date' => Carbon::today()->subDay()->format('Y-m-d')],
]
],
[
'title' => 'TDD - Test Driven Drupal',
'events' => [
'',
['date' => Carbon::today()->subDay()->format('Y-m-d')],
]
],
];
@ -75,6 +76,29 @@ final class TalkExtensionTest extends TestCase
/** @test */
public function it_excludes_future_talks(): void
{
$this->markTestIncomplete();
$talks = [
[
'title' => 'Building static sites with Sculpin',
'events' => [
[
'date' => Carbon::today()
->subDay()
->format('Y-m-d'),
],
],
],
[
'title' => 'TDD - Test Driven Drupal',
'events' => [
[
'date' => Carbon::today()
->addDay()
->format('Y-m-d'),
],
],
],
];
$this->assertSame(1, $this->subject->getPastTalkCount($talks));
}
}