Passed
Push — master ( 801c67...317e2e )
by WEBEWEB
04:00
created

testCoreNativeMethodFunction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
c 0
b 0
f 0
dl 0
loc 9
rs 10
cc 1
nc 1
nop 0
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"]));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $obj->coreNativeMethodFu...ll, array('exception')) targeting WBW\Bundle\CoreBundle\Tw...eNativeMethodFunction() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

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.

Loading history...
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"));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $obj->coreStaticMethodFunction(null, 'exception') targeting WBW\Bundle\CoreBundle\Tw...eStaticMethodFunction() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

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.

Loading history...
54
        $this->assertEquals(null, $obj->coreStaticMethodFunction("exception", null));
0 ignored issues
show
Bug introduced by
Are you sure the usage of $obj->coreStaticMethodFunction('exception', null) targeting WBW\Bundle\CoreBundle\Tw...eStaticMethodFunction() seems to always return null.

This check looks for function or method calls that always return null and whose return value is used.

class A
{
    function getObject()
    {
        return null;
    }

}

$a = new A();
if ($a->getObject()) {

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.

Loading history...
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