Completed
Pull Request — master (#22)
by
unknown
02:22
created

SmokeTestRunCommandTest::setCommandConfiguration()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Smartbox\CoreBundle\Tests\Command;
4
5
use JMS\Serializer\SerializerInterface;
6
use Smartbox\CoreBundle\Utils\SmokeTest\Output\SmokeTestOutputInterface;
7
use Smartbox\CoreBundle\Utils\SmokeTest\SmokeTestInterface;
8
use Symfony\Bundle\FrameworkBundle\Console\Application;
9
use Smartbox\CoreBundle\Command\SmokeTestRunCommand;
10
use Symfony\Bundle\FrameworkBundle\Test\KernelTestCase;
11
use Symfony\Component\Console\Command\Command;
12
use Symfony\Component\Console\Input\ArrayInput;
13
use Symfony\Component\Console\Output\NullOutput;
14
use Symfony\Component\Console\Tester\CommandTester;
15
use Symfony\Component\Console\Input\InputInterface;
16
use Symfony\Component\DependencyInjection\ContainerInterface;
17
18
/**
19
 * @group smoke-test
20
 */
21
class SmokeTestRunCommandTest extends KernelTestCase
22
{
23
24
    /**
25
     * @var Application
26
     */
27
    private $application;
28
29
    /**
30
     * @var SerializerInterface
31
     */
32
    private $serializer;
33
34
    /**
35
     * @var Container
36
     */
37
    private $container;
38
39
    /**
40
     * @var array
41
     */
42
    private $commandConfiguration = [];
43
44
    /**
45
     * @var Command
46
     */
47
    private $command;
48
49
    /**
50
     * @var CommandTester
51
     */
52
    private $commandTester;
53
54
    public function setUp()
55
    {
56
        $kernel = $this->createKernel();
57
        $kernel->boot();
58
59
        $this->application = new Application($kernel);
60
        $this->application->add(new SmokeTestRunCommand());
61
62
        $this->container = $kernel->getContainer();
0 ignored issues
show
Documentation Bug introduced by
It seems like $kernel->getContainer() of type object<Symfony\Component...ion\ContainerInterface> is incompatible with the declared type object<Smartbox\CoreBund...ests\Command\Container> 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...
63
64
        $this->serializer = $this->container->get('jms_serializer');
65
66
        $this->command = $this->application->find('smartbox:smoke-test');
67
        $this->commandTester = new CommandTester($this->command);
68
    }
69
70
    public function tearDown()
71
    {
72
        parent::tearDown(); // TODO: Change the autogenerated stub
73
    }
74
75 View Code Duplication
    public function testSmokeTestCommandNoLabels()
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...
76
    {
77
        $smokeTestInput = $this->createMock(InputInterface::class);
0 ignored issues
show
Unused Code introduced by
$smokeTestInput is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
78
79
        $smokeTestOutput = $this->createMock(SmokeTestOutputInterface::class);
80
        $smokeTestOutput->expects($this->any())->method('isOK')->will($this->returnValue(true));
81
        $smokeTestOutput->expects($this->any())->method('getMessages')->will($this->returnValue([]));
82
83
        $smokeTest1 = $this->createMock(SmokeTestInterface::class);
84
        $smokeTest1->expects($this->never())->method('run')->will($this->returnValue($smokeTestOutput));
85
        $smokeTest1->expects($this->never())->method('getDescription');
86
87
        $smokeTest2 = $this->createMock(SmokeTestInterface::class);
88
        $smokeTest2->expects($this->once())->method('run')->will($this->returnValue($smokeTestOutput));
89
        $smokeTest2->expects($this->once())->method('getDescription');
90
91
        $smokeTestRunCommand = new SmokeTestRunCommand();
92
        $smokeTestRunCommand->addTest('id1', $smokeTest1, 'run', 'getDescription', ['wip']);
93
        $smokeTestRunCommand->addTest('id2', $smokeTest2, 'run', 'getDescription', ['critical']);
94
        
95
        $smokeTestRunCommand->run(new ArrayInput(['--label' => []]), new NullOutput());
96
    }
97
98 View Code Duplication
    public function testMockSmokeTestCommandWipLabel()
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...
99
    {
100
        $smokeTestInput = $this->createMock(InputInterface::class);
0 ignored issues
show
Unused Code introduced by
$smokeTestInput is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
101
102
        $smokeTestOutput = $this->createMock(SmokeTestOutputInterface::class);
103
        $smokeTestOutput->expects($this->any())->method('isOK')->will($this->returnValue(true));
104
        $smokeTestOutput->expects($this->any())->method('getMessages')->will($this->returnValue([]));
105
106
        $smokeTest1 = $this->createMock(SmokeTestInterface::class);
107
        $smokeTest1->expects($this->once())->method('run')->will($this->returnValue($smokeTestOutput));
108
        $smokeTest1->expects($this->once())->method('getDescription');
109
110
        $smokeTest2 = $this->createMock(SmokeTestInterface::class);
111
        $smokeTest2->expects($this->never())->method('run')->will($this->returnValue($smokeTestOutput));
112
        $smokeTest2->expects($this->never())->method('getDescription');
113
114
        $smokeTestRunCommand = new SmokeTestRunCommand();
115
        $smokeTestRunCommand->addTest('id1', $smokeTest1, 'run', 'getDescription', ['wip']);
116
        $smokeTestRunCommand->addTest('id2', $smokeTest2, 'run', 'getDescription', ['critical']);
117
118
        $smokeTestRunCommand->run(new ArrayInput(['--label' => ['wip']]), new NullOutput());
119
    }
120
121 View Code Duplication
    public function testMockSmokeTestCommandAllTests()
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...
122
    {
123
        $smokeTestInput = $this->createMock(InputInterface::class);
0 ignored issues
show
Unused Code introduced by
$smokeTestInput is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
124
125
        $smokeTestOutput = $this->createMock(SmokeTestOutputInterface::class);
126
        $smokeTestOutput->expects($this->any())->method('isOK')->will($this->returnValue(true));
127
        $smokeTestOutput->expects($this->any())->method('getMessages')->will($this->returnValue([]));
128
129
        $smokeTest1 = $this->createMock(SmokeTestInterface::class);
130
        $smokeTest1->expects($this->once())->method('run')->will($this->returnValue($smokeTestOutput));
131
        $smokeTest1->expects($this->once())->method('getDescription');
132
133
        $smokeTest2 = $this->createMock(SmokeTestInterface::class);
134
        $smokeTest2->expects($this->once())->method('run')->will($this->returnValue($smokeTestOutput));
135
        $smokeTest2->expects($this->once())->method('getDescription');
136
137
        $smokeTestRunCommand = new SmokeTestRunCommand();
138
        $smokeTestRunCommand->addTest('id1', $smokeTest1, 'run', 'getDescription', ['wip']);
139
        $smokeTestRunCommand->addTest('id2', $smokeTest2, 'run', 'getDescription', ['critical']);
140
141
        $smokeTestRunCommand->run(new ArrayInput(['--all' => true]), new NullOutput());
142
    }
143
144
    private function setCommandConfiguration($options = [])
145
    {
146
        $this->commandConfiguration = $options;
147
    }
148
149
    public function execute($options = [])
150
    {
151
        $this->commandTester->execute([
152
            'command' => $this->command->getName(),
153
        ],
154
            $this->commandConfiguration
155
        );
156
157
        return $this->commandTester->getDisplay();
158
    }
159
160
    /**
161
     * @group smoke-test-label
162
     */
163
    public function testExecute()
164
    {
165
        $output = $this->execute();
166
        $this->assertContains('Smoke Tests', $output);
167
        $this->assertTrue(is_string($output));
168
        $this->assertNotContains('Error', $output);
169
    }
170
171
    /**
172
     * @group smoke-test-label
173
     */
174
    public function testFilterByLabels()
175
    {
176
        $label = ['-l' => 'important'];
177
        $this->setCommandConfiguration($label);
178
        $output = $this->execute();
179
        $this->assertContains('Smoke Tests', $output);
180
        $this->assertTrue(is_string($output));
181
        $this->assertNotContains('Error', $output);
182
    }
183
184
    /**
185
     * @group smoke-test-silent
186
     */
187
    /*public function testSilentOption()
188
    {
189
        $options = ['-q'];
190
        $this->commandConfiguration = $options;
191
        $output = $this->execute();
192
        var_dump($output);die;
193
194
        $this->assertContains('Smoke Tests', $output);
195
        $this->assertTrue(is_string($output));
196
        $this->assertNotContains('Error', $output);
197
    }*/
198
199
}
200