Completed
Push — master ( 1db3cd...632e40 )
by Jeroen
24:52 queued 11:31
created

KunstmaanVotingExtensionTest.php (2 issues)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\VotingBundle\Tests\DependencyInjection;
4
5
use Kunstmaan\VotingBundle\DependencyInjection\KunstmaanVotingExtension;
6
use PHPUnit\Framework\TestCase;
7
use Symfony\Component\DependencyInjection\ContainerBuilder;
8
9
class KunstmaanVotingExtensionTest extends TestCase
10
{
11
    /**
12
     * @var KunstmaanVotingExtension
13
     */
14
    private $extension;
15
16
    /**
17
     * Root name of the configuration
18
     *
19
     * @var string
20
     */
21
    private $root;
22
23
    public function setUp()
24
    {
25
        parent::setUp();
26
27
        $this->extension = $this->getExtension();
28
        $this->root = 'kuma_voting';
29
    }
30
31 View Code Duplication
    public function testGetConfigWithOverrideDefaultValue()
0 ignored issues
show
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...
32
    {
33
        $container = $this->getContainer();
34
        $container->setParameter('voting_default_value', 2);
35
        $this->extension->load([['actions' => [['name' => 'foo', 'max_number_by_ip' => 2]]]], $container);
36
        $this->assertTrue($container->hasParameter($this->root . '.actions'));
37
        $this->assertTrue(is_array($container->getParameter($this->root . '.actions')));
38
39
        $actions = $container->getParameter($this->root . '.actions');
40
        if (isset($actions['up_vote'])) {
41
            $this->assertEquals(2, $actions['up_vote']['default_value']);
42
        }
43
        if (isset($actions['down_vote'])) {
44
            $this->assertEquals(-2, $actions['down_vote']['default_value']);
45
        }
46
        if (isset($actions['facebook_like'])) {
47
            $this->assertEquals(2, $actions['facebook_like']['default_value']);
48
        }
49
    }
50
51
    public function testGetConfigWithDefaultValues()
52
    {
53
        $container = $this->getContainer();
54
        $this->extension->load(array(array()), $container);
55
        $this->assertTrue($container->hasParameter($this->root . '.actions'));
56
        $this->assertTrue(is_array($container->getParameter($this->root . '.actions')));
57
58
        $actions = $container->getParameter($this->root . '.actions');
59
        if (isset($actions['up_vote'])) {
60
            $this->assertEquals(1, $actions['up_vote']['default_value']);
61
        }
62
        if (isset($actions['down_vote'])) {
63
            $this->assertEquals(-1, $actions['down_vote']['default_value']);
64
        }
65
        if (isset($actions['facebook_like'])) {
66
            $this->assertEquals(1, $actions['facebook_like']['default_value']);
67
        }
68
    }
69
70 View Code Duplication
    public function testGetConfigWithOverrideValues()
0 ignored issues
show
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...
71
    {
72
        $configs = array(
73
            'actions' => array(
74
                'up_vote' => array(
75
                    'default_value' => '2',
76
                ),
77
                'down_vote' => array(
78
                    'default_value' => '-5',
79
                ),
80
            ),
81
        );
82
83
        $container = $this->getContainer();
84
        $this->extension->load(array($configs), $container);
85
        $this->assertTrue($container->hasParameter($this->root . '.actions'));
86
        $this->assertTrue(is_array($container->getParameter($this->root . '.actions')));
87
88
        $actions = $container->getParameter($this->root . '.actions');
89
        if (isset($actions['up_vote'])) {
90
            $this->assertEquals(2, $actions['up_vote']['default_value']);
91
        }
92
        if (isset($actions['down_vote'])) {
93
            $this->assertEquals(-5, $actions['down_vote']['default_value']);
94
        }
95
        if (isset($actions['facebook_like'])) {
96
            $this->assertEquals(1, $actions['facebook_like']['default_value']);
97
        }
98
    }
99
100
    /**
101
     * @return KunstmaanVotingExtension
102
     */
103
    protected function getExtension()
104
    {
105
        return new KunstmaanVotingExtension();
106
    }
107
108
    /**
109
     * @return ContainerBuilder
110
     */
111
    private function getContainer()
112
    {
113
        return new ContainerBuilder();
114
    }
115
}
116