summaryrefslogtreecommitdiff
path: root/tests/Unit/Renderer/Twig/Extensions/ExtensionTest.php
blob: 10f2e69a549f8543320ae01466d3e272b5a4009b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?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 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));
    }
}