Completed
Push — master ( 06c1ce...67d37c )
by Jeroen
06:20
created

KunstmaanVotingExtensionTest.php (3 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()
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->assertInternalType('array', $container->getParameter($this->root . '.actions'));
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\Assert::assertInternalType() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3369

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
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->assertInternalType('array', $container->getParameter($this->root . '.actions'));
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\Assert::assertInternalType() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3369

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
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()
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->assertInternalType('array', $container->getParameter($this->root . '.actions'));
0 ignored issues
show
Deprecated Code introduced by
The method PHPUnit\Framework\Assert::assertInternalType() has been deprecated with message: https://github.com/sebastianbergmann/phpunit/issues/3369

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

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