diff options
Diffstat (limited to 'tests/Unit/Renderer/Twig/Extensions/ExtensionTest.php')
-rw-r--r-- | tests/Unit/Renderer/Twig/Extensions/ExtensionTest.php | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/tests/Unit/Renderer/Twig/Extensions/ExtensionTest.php b/tests/Unit/Renderer/Twig/Extensions/ExtensionTest.php new file mode 100644 index 00000000..e1c5a378 --- /dev/null +++ b/tests/Unit/Renderer/Twig/Extensions/ExtensionTest.php @@ -0,0 +1,84 @@ +<?php + +namespace Engelsystem\Test\Unit\Renderer\Twig\Extensions; + +use PHPUnit\Framework\TestCase; +use Twig_Function as TwigFunction; + +abstract class ExtensionTest extends TestCase +{ + /** + * Assert that a twig filter was registered + * + * @param string $name + * @param callable $callback + * @param TwigFunction[] $functions + */ + protected function assertFilterExists($name, $callback, $functions) + { + foreach ($functions as $function) { + if ($function->getName() != $name) { + continue; + } + + $this->assertEquals($callback, $function->getCallable()); + return; + } + + $this->fail(sprintf('Filter %s not found', $name)); + } + + /** + * Assert that a twig function was registered + * + * @param string $name + * @param callable $callback + * @param TwigFunction[] $functions + */ + protected function assertExtensionExists($name, $callback, $functions) + { + foreach ($functions as $function) { + if ($function->getName() != $name) { + continue; + } + + $this->assertEquals($callback, $function->getCallable()); + return; + } + + $this->fail(sprintf('Function %s not found', $name)); + } + + /** + * Assert that a global exists + * + * @param string $name + * @param mixed $value + * @param mixed[] $globals + */ + protected function assertGlobalsExists($name, $value, $globals) + { + if (isset($globals[$name])) { + $this->assertArraySubset([$name => $value], $globals); + + return; + } + + $this->fail(sprintf('Global %s not found', $name)); + } + + /** + * Assert that a token parser was set + * + * @param $tokenParser + * @param $tokenParsers + */ + protected function assertTokenParserExists($tokenParser, $tokenParsers) + { + $this->assertArraySubset( + [$tokenParser], + $tokenParsers, + sprintf('Token parser %s not found', get_class($tokenParser)) + ); + } +} |