-
Notifications
You must be signed in to change notification settings - Fork 40
/
RunCommandIntegrationTest.php
177 lines (153 loc) · 6.4 KB
/
RunCommandIntegrationTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
<?php declare(strict_types=1);
namespace Lmc\Steward\Console\Command;
use Lmc\Steward\Console\Application;
use PHPUnit\Framework\TestCase;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\EventDispatcher\EventDispatcher;
/**
* Run command tests that require real Selenium server to execute the tests.
*
* @covers \Lmc\Steward\Console\Command\RunCommand
* @covers \Lmc\Steward\Listener\WebDriverListener
* @covers \Lmc\Steward\Process\ExecutionLoop
* @group integration
* @runTestsInSeparateProcesses
*/
class RunCommandIntegrationTest extends TestCase
{
/** @var RunCommand */
protected $command;
/** @var CommandTester */
protected $tester;
protected function setUp(): void
{
$dispatcher = new EventDispatcher();
$application = new Application();
$application->add(new RunCommand($dispatcher));
/** @var RunCommand $command */
$command = $application->find('run');
$this->command = $command;
$this->tester = new CommandTester($this->command);
}
/**
* @dataProvider provideExpectedTestOutput
*/
public function testShouldExecuteSimpleTests(int $outputVerbosity, string $expectedOutputFile): void
{
$this->tester->execute(
[
'command' => $this->command->getName(),
'environment' => 'staging',
'browser' => 'chrome',
'--tests-dir' => __DIR__ . '/Fixtures/SimpleTests',
],
['verbosity' => $outputVerbosity]
);
$output = $this->tester->getDisplay();
$this->assertStringMatchesFormatFile(__DIR__ . '/Fixtures/SimpleTests/' . $expectedOutputFile, $output);
$this->assertSame(0, $this->tester->getStatusCode());
// Make sure the results were written to results file
/** @var \SimpleXMLElement $xml */
$xml = simplexml_load_file(STEWARD_BASE_DIR . '/logs/results.xml');
$simpleTest = $xml->testcase[1];
$dependantTest = $xml->testcase[0];
$this->assertInstanceOf(\SimpleXMLElement::class, $xml->testcase);
$this->assertCount(2, $xml->testcase);
$this->assertEquals('Lmc\Steward\Console\Command\Fixtures\SimpleTests\DependantTest', $dependantTest['name']);
$this->assertEquals('Lmc\Steward\Console\Command\Fixtures\SimpleTests\SimpleTest', $simpleTest['name']);
$this->assertEquals('done', $dependantTest['status']);
$this->assertEquals('done', $simpleTest['status']);
$this->assertEquals('passed', $dependantTest['result']);
$this->assertEquals('passed', $simpleTest['result']);
$this->assertInstanceOf(\SimpleXMLElement::class, $simpleTest->test);
$this->assertCount(1, $simpleTest->test);
$this->assertEquals('testWebpage', $simpleTest->test['name']);
$this->assertEquals('done', $simpleTest->test['status']);
$this->assertEquals('passed', $simpleTest->test['result']);
}
/**
* @return array[]
*/
public function provideExpectedTestOutput(): array
{
return [
[OutputInterface::VERBOSITY_NORMAL, 'expected-normal-output.txt'],
[OutputInterface::VERBOSITY_VERBOSE, 'expected-verbose-output.txt'],
[OutputInterface::VERBOSITY_VERY_VERBOSE, 'expected-very-verbose-output.txt'],
[OutputInterface::VERBOSITY_DEBUG, 'expected-debug-output.txt'],
];
}
public function testShouldExecuteTestsThatDontNeedBrowser(): void
{
$this->tester->execute(
[
'command' => $this->command->getName(),
'environment' => 'staging',
'browser' => 'internet explorer', // intentionally use unavailable browser to make sure it is not used
'--tests-dir' => __DIR__ . '/Fixtures/NoBrowserTests',
],
['verbosity' => OutputInterface::VERBOSITY_DEBUG]
);
$output = $this->tester->getDisplay();
$this->assertStringMatchesFormatFile(__DIR__ . '/Fixtures/NoBrowserTests/expected-output.txt', $output);
$this->assertSame(0, $this->tester->getStatusCode());
}
/**
* @dataProvider provideExpectedFailingTestOutput
*/
public function testShouldProcessFailedTests(int $outputVerbosity, string $expectedOutputFile): void
{
$this->tester->execute(
[
'command' => $this->command->getName(),
'environment' => 'staging',
'browser' => 'chrome',
'--tests-dir' => __DIR__ . '/Fixtures/FailingTests',
],
['verbosity' => $outputVerbosity]
);
$output = $this->tester->getDisplay();
$this->assertStringMatchesFormatFile(__DIR__ . '/Fixtures/FailingTests/' . $expectedOutputFile, $output);
$this->assertSame(1, $this->tester->getStatusCode());
}
/**
* @return array[]
*/
public function provideExpectedFailingTestOutput(): array
{
return [
[OutputInterface::VERBOSITY_NORMAL, 'expected-normal-output.txt'],
[OutputInterface::VERBOSITY_VERBOSE, 'expected-verbose-output.txt'],
[OutputInterface::VERBOSITY_VERY_VERBOSE, 'expected-very-verbose-output.txt'],
[OutputInterface::VERBOSITY_DEBUG, 'expected-debug-output.txt'],
];
}
public function testShouldExitWithCode0EvenWithFailedTestsWhenNoExitOptionIsPassed(): void
{
$this->tester->execute(
[
'command' => $this->command->getName(),
'environment' => 'staging',
'browser' => 'chrome',
'--no-exit' => true,
'--tests-dir' => __DIR__ . '/Fixtures/FailingTests',
],
['verbosity' => OutputInterface::VERBOSITY_DEBUG]
);
$this->assertSame(0, $this->tester->getStatusCode());
}
public function testShouldNotStartBrowserForSkippedTests(): void
{
$this->tester->execute(
[
'command' => $this->command->getName(),
'environment' => 'staging',
'browser' => 'chrome',
'--tests-dir' => __DIR__ . '/Fixtures/SkippedTests',
],
['verbosity' => OutputInterface::VERBOSITY_DEBUG]
);
$this->assertSame(1, mb_substr_count($this->tester->getDisplay(), 'Initializing "chrome" WebDriver'));
}
}