-
Notifications
You must be signed in to change notification settings - Fork 58
/
RunningToolTest.php
72 lines (63 loc) · 2.53 KB
/
RunningToolTest.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
<?php
namespace Edge\QA;
class RunningToolTest extends \PHPUnit_Framework_TestCase
{
private $errorsCountInXmlFile = 2;
public function testBuildOptionWithDefinedSeparator()
{
$tool = new RunningTool('tool', ['optionSeparator' => ' ']);
assertThat($tool->buildOption('option', ''), is('--option'));
assertThat($tool->buildOption('option', 'value'), is('--option value'));
assertThat($tool->buildOption('option', 0), is('--option 0'));
}
public function testMarkSuccessWhenXPathIsNotDefined()
{
$tool = new RunningTool('tool', ['errorsXPath' => null]);
assertThat($tool->analyzeResult(), is([true, '']));
}
public function testMarkFailureWhenXmlFileDoesNotExist()
{
$tool = new RunningTool('tool', [
'xml' => ['non-existent.xml'],
'errorsXPath' => '//errors/error',
]);
assertThat($tool->analyzeResult(), is([false, 0]));
}
/** @dataProvider provideAllowedErrors */
public function testCompareAllowedCountWithErrorsCountFromXml($allowedErrors, $isOk)
{
$tool = new RunningTool('tool', [
'xml' => ['tests/Error/errors.xml'],
'errorsXPath' => '//errors/error',
'allowedErrorsCount' => $allowedErrors
]);
assertThat($tool->analyzeResult(), is([$isOk, $this->errorsCountInXmlFile]));
}
public function provideAllowedErrors()
{
return [
'success when allowed errors are not defined' => [null, true],
'success when errors count <= allowed count' => [$this->errorsCountInXmlFile, true],
'failure when errors count > allowed count' => [$this->errorsCountInXmlFile - 1, false],
];
}
/** @dataProvider provideProcess */
public function testAnalyzeExitCodeInCliMode($allowedErrors, $exitCode, array $expectedResult)
{
$tool = new RunningTool('tool', [
'allowedErrorsCount' => $allowedErrors
]);
$tool->process = $this->prophesize('Symfony\Component\Process\Process')
->getExitCode()->willReturn($exitCode)
->getObjectProphecy()->reveal();
assertThat($tool->analyzeResult(true), is($expectedResult));
}
public function provideProcess()
{
return [
'success when exit code = 0' => [0, 0, [true, 0]],
'success when exit code <= allowed code' => [1, 1, [true, 1]],
'failure when errors count > allowed count but errors count is always one' => [0, 2, [false, 1]],
];
}
}