testCoreStaticMethodFunction()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 10
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\TwigFunction;
16
use WBW\Bundle\CoreBundle\Tests\AbstractTestCase;
17
use WBW\Bundle\CoreBundle\Twig\Extension\ContainerTwigExtension;
18
19
/**
20
 * Container Twig extension test.
21
 *
22
 * @author webeweb <https://github.com/webeweb>
23
 * @package WBW\Bundle\CoreBundle\Tests\Twig\Extension
24
 */
25
class ContainerTwigExtensionTest extends AbstractTestCase {
26
27
    /**
28
     * Test coreNativeMethodFunction()
29
     *
30
     * @return void
31
     */
32
    public function testCoreNativeMethodFunction(): void {
33
34
        $obj = new ContainerTwigExtension($this->twigEnvironment, $this->containerBuilder);
35
36
        $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...
37
        $this->assertEquals(null, $obj->coreNativeMethodFunction("exception", [null]));
38
39
        $this->assertEquals(false, $obj->coreNativeMethodFunction("is_array", ["isWindows"]));
40
        $this->assertEquals("'isWindows'", $obj->coreNativeMethodFunction("var_export", ["isWindows", true]));
41
    }
42
43
    /**
44
     * Test coreStaticMethodFunction()
45
     *
46
     * @return void
47
     */
48
    public function testCoreStaticMethodFunction(): void {
49
50
        $obj = new ContainerTwigExtension($this->twigEnvironment, $this->containerBuilder);
51
52
        $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...
53
        $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...
54
        $this->assertEquals(null, $obj->coreStaticMethodFunction("WBW\\Library\\System\\Helper\\SystemHelper", "isMacOs"));
55
56
        $this->assertEquals("\\" === DIRECTORY_SEPARATOR, $obj->coreStaticMethodFunction("WBW\\Library\\System\\Helper\\SystemHelper", "isWindows"));
57
        $this->assertEquals('<div id="id">content</div>', $obj->coreStaticMethodFunction("WBW\\Bundle\\CoreBundle\\Twig\\Extension\\AbstractTwigExtension", "coreHtmlElement", ["div", "content", ["id" => "id"]]));
58
    }
59
60
    /**
61
     * Test getContainerParameterFunction()
62
     *
63
     * @return void
64
     */
65
    public function testGetContainerParameterFunction(): void {
66
67
        $obj = new ContainerTwigExtension($this->twigEnvironment, $this->containerBuilder);
68
69
        $this->assertNotNull($obj->getContainerParameterFunction("kernel.project_dir"));
70
    }
71
72
    /**
73
     * Test getFunctions()
74
     *
75
     * @return void
76
     */
77
    public function testGetFunctions(): void {
78
79
        $obj = new ContainerTwigExtension($this->twigEnvironment, $this->containerBuilder);
80
81
        $res = $obj->getFunctions();
82
        $this->assertCount(3, $res);
83
84
        $i = -1;
85
86
        $this->assertInstanceOf(TwigFunction::class, $res[++$i]);
87
        $this->assertEquals("getContainerParameter", $res[$i]->getName());
88
        $this->assertEquals([$obj, "getContainerParameterFunction"], $res[$i]->getCallable());
89
90
        $this->assertInstanceOf(TwigFunction::class, $res[++$i]);
91
        $this->assertEquals("coreNativeMethod", $res[$i]->getName());
92
        $this->assertEquals([$obj, "coreNativeMethodFunction"], $res[$i]->getCallable());
93
94
        $this->assertInstanceOf(TwigFunction::class, $res[++$i]);
95
        $this->assertEquals("coreStaticMethod", $res[$i]->getName());
96
        $this->assertEquals([$obj, "coreStaticMethodFunction"], $res[$i]->getCallable());
97
    }
98
99
    /**
100
     * Test __construct()
101
     *
102
     * @return void
103
     */
104
    public function test__construct(): void {
105
106
        $this->assertEquals("wbw.core.twig.extension.container", ContainerTwigExtension::SERVICE_NAME);
107
108
        $obj = new ContainerTwigExtension($this->twigEnvironment, $this->containerBuilder);
109
110
        $this->assertInstanceOf(ExtensionInterface::class, $obj);
111
112
        $this->assertSame($this->twigEnvironment, $obj->getTwigEnvironment());
113
        $this->assertSame($this->containerBuilder, $obj->getContainer());
114
    }
115
}
116