1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the core-bundle package. |
5
|
|
|
* |
6
|
|
|
* (c) 2019 WEBEWEB |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace WBW\Bundle\CoreBundle\Tests\Twig\Extension; |
13
|
|
|
|
14
|
|
|
use Twig\Extension\ExtensionInterface; |
15
|
|
|
use Twig\Node\Node; |
16
|
|
|
use Twig\TwigFunction; |
17
|
|
|
use WBW\Bundle\CoreBundle\Tests\AbstractTestCase; |
18
|
|
|
use WBW\Bundle\CoreBundle\Twig\Extension\ContainerTwigExtension; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Container Twig extension test. |
22
|
|
|
* |
23
|
|
|
* @author webeweb <https://github.com/webeweb> |
24
|
|
|
* @package WBW\Bundle\CoreBundle\Tests\Twig\Extension |
25
|
|
|
*/ |
26
|
|
|
class ContainerTwigExtensionTest extends AbstractTestCase { |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Tests coreNativeMethodFunction() |
30
|
|
|
* |
31
|
|
|
* @return void |
32
|
|
|
*/ |
33
|
|
|
public function testCoreNativeMethodFunction(): void { |
34
|
|
|
|
35
|
|
|
$obj = new ContainerTwigExtension($this->twigEnvironment, $this->containerBuilder); |
36
|
|
|
|
37
|
|
|
$this->assertEquals(null, $obj->coreNativeMethodFunction(null, ["exception"])); |
|
|
|
|
38
|
|
|
$this->assertEquals(null, $obj->coreNativeMethodFunction("exception", [null])); |
39
|
|
|
|
40
|
|
|
$this->assertEquals(false, $obj->coreNativeMethodFunction("is_array", ["isWindows"])); |
41
|
|
|
$this->assertEquals("'isWindows'", $obj->coreNativeMethodFunction("var_export", ["isWindows", true])); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* Tests coreStaticMethodFunction() |
46
|
|
|
* |
47
|
|
|
* @return void |
48
|
|
|
*/ |
49
|
|
|
public function testCoreStaticMethodFunction(): void { |
50
|
|
|
|
51
|
|
|
$obj = new ContainerTwigExtension($this->twigEnvironment, $this->containerBuilder); |
52
|
|
|
|
53
|
|
|
$this->assertEquals(null, $obj->coreStaticMethodFunction(null, "exception")); |
|
|
|
|
54
|
|
|
$this->assertEquals(null, $obj->coreStaticMethodFunction("exception", null)); |
|
|
|
|
55
|
|
|
$this->assertEquals(null, $obj->coreStaticMethodFunction("WBW\\Library\\System\\Helper\\SystemHelper", "isMacOs")); |
56
|
|
|
|
57
|
|
|
$this->assertEquals("\\" === DIRECTORY_SEPARATOR, $obj->coreStaticMethodFunction("WBW\\Library\\System\\Helper\\SystemHelper", "isWindows")); |
58
|
|
|
$this->assertEquals('<div id="id">content</div>', $obj->coreStaticMethodFunction("WBW\\Bundle\\CoreBundle\\Twig\\Extension\\AbstractTwigExtension", "coreHtmlElement", ["div", "content", ["id" => "id"]])); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Tests getContainerParameterFunction() |
63
|
|
|
* |
64
|
|
|
* @return void |
65
|
|
|
*/ |
66
|
|
|
public function testGetContainerParameterFunction(): void { |
67
|
|
|
|
68
|
|
|
$obj = new ContainerTwigExtension($this->twigEnvironment, $this->containerBuilder); |
69
|
|
|
|
70
|
|
|
$this->assertNotNull($obj->getContainerParameterFunction("kernel.project_dir")); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Tests getFunctions() |
75
|
|
|
* |
76
|
|
|
* @return void |
77
|
|
|
*/ |
78
|
|
|
public function testGetFunctions(): void { |
79
|
|
|
|
80
|
|
|
$obj = new ContainerTwigExtension($this->twigEnvironment, $this->containerBuilder); |
81
|
|
|
|
82
|
|
|
$res = $obj->getFunctions(); |
83
|
|
|
$this->assertCount(3, $res); |
84
|
|
|
|
85
|
|
|
$i = -1; |
86
|
|
|
|
87
|
|
|
$this->assertInstanceOf(TwigFunction::class, $res[++$i]); |
88
|
|
|
$this->assertEquals("getContainerParameter", $res[$i]->getName()); |
89
|
|
|
$this->assertEquals([$obj, "getContainerParameterFunction"], $res[$i]->getCallable()); |
90
|
|
|
|
91
|
|
|
$this->assertInstanceOf(TwigFunction::class, $res[++$i]); |
92
|
|
|
$this->assertEquals("coreNativeMethod", $res[$i]->getName()); |
93
|
|
|
$this->assertEquals([$obj, "coreNativeMethodFunction"], $res[$i]->getCallable()); |
94
|
|
|
|
95
|
|
|
$this->assertInstanceOf(TwigFunction::class, $res[++$i]); |
96
|
|
|
$this->assertEquals("coreStaticMethod", $res[$i]->getName()); |
97
|
|
|
$this->assertEquals([$obj, "coreStaticMethodFunction"], $res[$i]->getCallable()); |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Tests __construct() |
102
|
|
|
* |
103
|
|
|
* @return void |
104
|
|
|
*/ |
105
|
|
|
public function test__construct(): void { |
106
|
|
|
|
107
|
|
|
$this->assertEquals("wbw.core.twig.extension.container", ContainerTwigExtension::SERVICE_NAME); |
108
|
|
|
|
109
|
|
|
$obj = new ContainerTwigExtension($this->twigEnvironment, $this->containerBuilder); |
110
|
|
|
|
111
|
|
|
$this->assertInstanceOf(ExtensionInterface::class, $obj); |
112
|
|
|
|
113
|
|
|
$this->assertSame($this->twigEnvironment, $obj->getTwigEnvironment()); |
114
|
|
|
$this->assertSame($this->containerBuilder, $obj->getContainer()); |
115
|
|
|
} |
116
|
|
|
} |
117
|
|
|
|
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.