Skip to content

Commit

Permalink
Use first class callable syntax to let Psalm know these are used
Browse files Browse the repository at this point in the history
Or ignore if that's not enough

# Conflicts:
#	site/psalm.xml
  • Loading branch information
spaze committed Aug 23, 2023
1 parent 397460c commit c16911b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
14 changes: 7 additions & 7 deletions site/app/Templating/Filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ public function __construct(
public function getAll(): array
{
return [
'staticUrl' => [$this, 'staticUrl'],
'staticImageUrl' => [$this, 'staticImageUrl'],
'format' => [$this, 'format'],
'localeDay' => [$this->dateTimeFormatter, 'localeDay'],
'localeMonth' => [$this->dateTimeFormatter, 'localeMonth'],
'localeIntervalDay' => [$this->dateTimeFormatter, 'localeIntervalDay'],
'localeIntervalMonth' => [$this->dateTimeFormatter, 'localeIntervalMonth'],
'staticUrl' => $this->staticUrl(...),
'staticImageUrl' => $this->staticImageUrl(...),
'format' => $this->format(...),
'localeDay' => $this->dateTimeFormatter->localeDay(...),
'localeMonth' => $this->dateTimeFormatter->localeMonth(...),
'localeIntervalDay' => $this->dateTimeFormatter->localeIntervalDay(...),
'localeIntervalMonth' => $this->dateTimeFormatter->localeIntervalMonth(...),
];
}

Expand Down
6 changes: 6 additions & 0 deletions site/tests/Templating/TemplateFactoryTest.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ declare(strict_types = 1);

namespace MichalSpacekCz\Templating;

use DateTimeImmutable;
use MichalSpacekCz\Templating\Exceptions\WrongTemplateClassException;
use Nette\Bridges\ApplicationLatte\DefaultTemplate;
use Nette\Bridges\ApplicationLatte\LatteFactory;
use Nette\Bridges\ApplicationLatte\Template;
use Nette\InvalidArgumentException;
use Spaze\NonceGenerator\Nonce;
use Tester\Assert;
use Tester\FileMock;
use Tester\TestCase;

$runner = require __DIR__ . '/../bootstrap.php';
Expand All @@ -29,11 +31,15 @@ class TemplateFactoryTest extends TestCase

public function testCreateTemplate(): void
{
$file = FileMock::create('{="/foo.png"|staticUrl}, {="/bar.png"|staticImageUrl}, {="**baz**"|format}, {$start|localeDay}, {$start|localeMonth}, {$start|localeIntervalDay:$end}, {$start|localeIntervalMonth:$end}');
$template = $this->templateFactory->createTemplate();
$template->start = new DateTimeImmutable('2023-08-23');
$template->end = new DateTimeImmutable('2023-09-03');
Assert::type(DefaultTemplate::class, $template);
$providers = $template->getLatte()->getProviders();
Assert::hasKey('uiNonce', $providers);
Assert::same($this->nonce->getValue(), $providers['uiNonce']);
Assert::same('https://www.domain.example/foo.png, https://www.domain.example/i/images/bar.png, <strong>baz</strong>, 23. srpna 2023, srpen 2023, 23. srpna – 3. září 2023, srpen–září 2023', $template->renderToString($file));
}


Expand Down

0 comments on commit c16911b

Please sign in to comment.