Completed
Push — master ( bf375b...cc5661 )
by Rafał
07:07
created

ContainerNodeTest::getTests()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 67
Code Lines 22

Duplication

Lines 67
Ratio 100 %

Importance

Changes 0
Metric Value
dl 67
loc 67
rs 9.2815
c 0
b 0
f 0
cc 1
eloc 22
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * This file is part of the Superdesk Web Publisher Templates System.
5
 *
6
 * Copyright 2015 Sourcefabric z.ú. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2015 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Component\TemplatesSystem\Tests\Twig\Node;
16
17
use SWP\Component\TemplatesSystem\Twig\Node\ContainerNode;
18
19
class ContainerNodeTest extends \Twig_Test_NodeTestCase
20
{
21 View Code Duplication
    public function testConstructor()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
22
    {
23
        $name = new \Twig_Node([new \Twig_Node_Expression_Constant('container_name', 1)]);
24
        $parameters = new \Twig_Node_Expression_Array([], 1);
25
        $body = new \Twig_Node_Text('', 1);
26
        $node = new ContainerNode($name, $parameters, $body, 1, 'gimme');
27
        $this->assertEquals($name, $node->getNode('name'));
28
        $this->assertEquals($parameters, $node->getNode('parameters'));
29
        $this->assertEquals($body, $node->getNode('body'));
30
    }
31
32 View Code Duplication
    public function getTests()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
33
    {
34
        $name1 = new \Twig_Node([new \Twig_Node_Expression_Constant('container_name', 1)]);
35
        $parameters1 = new \Twig_Node_Expression_Array([], 1);
36
        $body1 = new \Twig_Node_Text('Test body', 1);
37
        $node1 = new ContainerNode($name1, $parameters1, $body1, 1, 'gimme');
38
39
        $name2 = new \Twig_Node([new \Twig_Node_Expression_Constant('container_name', 2)]);
40
        $body2 = new \Twig_Node_Text('Test body', 2);
41
        $node2 = new ContainerNode($name2, null, $body2, 2, 'gimme');
42
43
        $name3 = new \Twig_Node([new \Twig_Node_Expression_Constant('container_name', 3)]);
44
        $parameters3 = new \Twig_Node_Expression_Array([new \Twig_Node_Expression_Constant('foo', 1), new \Twig_Node_Expression_Constant(true, 1)], 1);
45
        $body3 = new \Twig_Node_Text('Test body', 3);
46
        $node3 = new ContainerNode($name3, $parameters3, $body3, 3, 'gimme');
47
48
        return [
49
            [$node1, <<<'EOF'
50
// line 1
51
$containerService = $this->env->getExtension('swp_container')->getContainerService();
52
$container = $containerService->getContainer("container_name", array());
53
if ($container->isVisible()) {
54
    echo $container->renderOpenTag();
55
    if ($container->hasWidgets()) {
56
        echo $container->renderWidgets();
57
    } else {
58
        echo "Test body";
59
    }
60
    echo $container->renderCloseTag();
61
}
62
unset($container);unset($containerService);
63
EOF
64
            ],
65
            [$node2, <<<'EOF'
66
// line 2
67
$containerService = $this->env->getExtension('swp_container')->getContainerService();
68
$container = $containerService->getContainer("container_name", array());
69
if ($container->isVisible()) {
70
    echo $container->renderOpenTag();
71
    if ($container->hasWidgets()) {
72
        echo $container->renderWidgets();
73
    } else {
74
        echo "Test body";
75
    }
76
    echo $container->renderCloseTag();
77
}
78
unset($container);unset($containerService);
79
EOF
80
            ],
81
            [$node3, <<<'EOF'
82
// line 3
83
$containerService = $this->env->getExtension('swp_container')->getContainerService();
84
$container = $containerService->getContainer("container_name", array("foo" => true));
85
if ($container->isVisible()) {
86
    echo $container->renderOpenTag();
87
    if ($container->hasWidgets()) {
88
        echo $container->renderWidgets();
89
    } else {
90
        echo "Test body";
91
    }
92
    echo $container->renderCloseTag();
93
}
94
unset($container);unset($containerService);
95
EOF
96
            ],
97
        ];
98
    }
99
100 View Code Duplication
    protected function tearDown()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
101
    {
102
        $reflection = new \ReflectionObject($this);
103
        foreach ($reflection->getProperties() as $prop) {
104
            if (!$prop->isStatic() && 0 !== strpos($prop->getDeclaringClass()->getName(), 'PHPUnit_')) {
0 ignored issues
show
introduced by
Consider using $prop->class. There is an issue with getName() and APC-enabled PHP versions.
Loading history...
105
                $prop->setAccessible(true);
106
                $prop->setValue($this, null);
107
            }
108
        }
109
    }
110
}
111