RunnerManagerTest::testGetGroups()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 15
rs 9.7666
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Liip\MonitorBundle\Tests\Helper;
4
5
use Liip\MonitorBundle\Helper\RunnerManager;
6
7
class RunnerManagerTest extends \PHPUnit\Framework\TestCase
8
{
9
    /**
10
     * @var \PHPUnit_Framework_MockObject_MockObject
11
     */
12
    private $container;
13
14
    /**
15
     * @var RunnerManager
16
     */
17
    private $runnerManager;
18
19
    public function groupProvider()
20
    {
21
        return [
22
            [null],
23
            ['default'],
24
            ['test'],
25
        ];
26
    }
27
28
    /**
29
     * @dataProvider groupProvider
30
     *
31
     * @param string $group
32
     */
33
    public function testGetRunner($group)
34
    {
35
        $this->container
36
            ->expects($this->any())
37
            ->method('getParameter')
38
            ->with('liip_monitor.default_group')
39
            ->willReturn('default');
40
41
        $this->container
42
            ->expects($this->any())
43
            ->method('has')
44
            ->with('liip_monitor.runner_'.($group ?: 'default'))
45
            ->willReturn(true);
46
47
        $expectedResult = $this->getMockBuilder('Liip\MonitorBundle\Runner')->getMock();
48
49
        $this->container
50
            ->expects($this->any())
51
            ->method('get')
52
            ->with('liip_monitor.runner_'.($group ?: 'default'))
53
            ->willReturn($expectedResult);
54
55
        $result = $this->runnerManager->getRunner($group);
56
57
        $this->assertSame($expectedResult, $result);
58
    }
59
60
    public function testGetRunnerReturnsNull()
61
    {
62
        $this->container
63
            ->expects($this->any())
64
            ->method('has')
65
            ->with('liip_monitor.runner_testgroup')
66
            ->willReturn(false);
67
68
        $result = $this->runnerManager->getRunner('testgroup');
69
70
        $this->assertNull($result);
71
    }
72
73
    public function testGetRunners()
74
    {
75
        $this->container
76
            ->expects($this->any())
77
            ->method('getParameter')
78
            ->with('liip_monitor.runners')
79
            ->willReturn(['liip_monitor.runner_group_1', 'liip_monitor.runner_group_2']);
80
81
        $runnerMockBuilder = $this->getMockBuilder('Liip\MonitorBundle\Runner');
82
        $runner1 = $runnerMockBuilder->getMock();
83
        $runner2 = $runnerMockBuilder->getMock();
84
        $this->container
85
            ->expects($this->exactly(2))
86
            ->method('get')
87
            ->withConsecutive(
88
                ['liip_monitor.runner_group_1'],
89
                ['liip_monitor.runner_group_2']
90
            )
91
            ->willReturnOnConsecutiveCalls($runner1, $runner2);
92
93
        $result = $this->runnerManager->getRunners();
94
95
        $this->assertTrue(is_array($result));
96
        $this->assertCount(2, $result);
0 ignored issues
show
Documentation introduced by
$result is of type array, but the function expects a object<Countable>|object...nit\Framework\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
97
        $this->assertArrayHasKey('group_1', $result);
98
        $this->assertArrayHasKey('group_2', $result);
99
        $this->assertSame($runner1, $result['group_1']);
100
        $this->assertSame($runner2, $result['group_2']);
101
    }
102
103
    public function testGetGroups()
104
    {
105
        $this->container
106
            ->expects($this->any())
107
            ->method('getParameter')
108
            ->with('liip_monitor.runners')
109
            ->willReturn(['liip_monitor.runner_group_1', 'liip_monitor.runner_group_2']);
110
111
        $result = $this->runnerManager->getGroups();
112
113
        $this->assertTrue(is_array($result));
114
        $this->assertCount(2, $result);
0 ignored issues
show
Documentation introduced by
$result is of type array, but the function expects a object<Countable>|object...nit\Framework\iterable>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
115
        $this->assertContains('group_1', $result);
116
        $this->assertContains('group_2', $result);
117
    }
118
119
    public function testGetDefaultGroup()
120
    {
121
        $expectedResult = 'default';
122
123
        $this->container
124
            ->expects($this->any())
125
            ->method('getParameter')
126
            ->with('liip_monitor.default_group')
127
            ->willReturn($expectedResult);
128
129
        $result = $this->runnerManager->getDefaultGroup();
130
131
        $this->assertEquals($expectedResult, $result);
132
    }
133
134
    protected function setUp(): void
135
    {
136
        $this->container = $this->getMockBuilder('Symfony\Component\DependencyInjection\ContainerInterface')->getMock();
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->getMockBuilder('S...rInterface')->getMock() of type object<PHPUnit\Framework\MockObject\MockObject> is incompatible with the declared type object<PHPUnit_Framework_MockObject_MockObject> of property $container.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
137
138
        $this->runnerManager = new RunnerManager($this->container);
0 ignored issues
show
Documentation introduced by
$this->container is of type object<PHPUnit\Framework\MockObject\MockObject>, but the function expects a object<Symfony\Component...ion\ContainerInterface>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
139
    }
140
}
141