1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace RQuadling\Tests\PHPStan\ErrorFormatter; |
6
|
|
|
|
7
|
|
|
use DOMDocument; |
8
|
|
|
use Generator; |
9
|
|
|
use PHPStan\Command\ErrorFormatter\TestBaseFormatter; |
10
|
|
|
use RQuadling\PHPStan\ErrorFormatter\JunitErrorFormatter; |
11
|
|
|
|
12
|
|
|
class JunitErrorFormatterTest extends TestBaseFormatter |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* [dataFormatterOutputProvider description] |
16
|
|
|
* |
17
|
|
|
* @return \Generator<array<int, string|int>> |
|
|
|
|
18
|
|
|
*/ |
19
|
|
|
public function dataFormatterOutputProvider(): Generator |
20
|
|
|
{ |
21
|
|
|
yield [ |
22
|
|
|
'No errors', |
23
|
|
|
0, |
24
|
|
|
0, |
25
|
|
|
0, |
26
|
|
|
'<?xml version="1.0" encoding="UTF-8"?> |
27
|
|
|
<testsuite failures="0" name="phpstan" tests="0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/junit-team/junit5/r5.5.1/platform-tests/src/test/resources/jenkins-junit.xsd"> |
28
|
|
|
<testcase name="phpstan"/> |
29
|
|
|
</testsuite> |
30
|
|
|
', |
31
|
|
|
]; |
32
|
|
|
|
33
|
|
|
yield [ |
34
|
|
|
'One file error', |
35
|
|
|
1, |
36
|
|
|
1, |
37
|
|
|
0, |
38
|
|
|
'<?xml version="1.0" encoding="UTF-8"?> |
39
|
|
|
<testsuite failures="1" name="phpstan" tests="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/junit-team/junit5/r5.5.1/platform-tests/src/test/resources/jenkins-junit.xsd"> |
40
|
|
|
<testcase name="folder with unicode 😃/file name with "spaces" and unicode 😃.php:4"> |
41
|
|
|
<failure message="Foo" /> |
42
|
|
|
</testcase> |
43
|
|
|
</testsuite> |
44
|
|
|
', |
45
|
|
|
]; |
46
|
|
|
|
47
|
|
|
yield [ |
48
|
|
|
'One generic error', |
49
|
|
|
1, |
50
|
|
|
0, |
51
|
|
|
1, |
52
|
|
|
'<?xml version="1.0" encoding="UTF-8"?> |
53
|
|
|
<testsuite failures="1" name="phpstan" tests="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/junit-team/junit5/r5.5.1/platform-tests/src/test/resources/jenkins-junit.xsd"> |
54
|
|
|
<testcase name="Generic error"> |
55
|
|
|
<failure message="first generic error" /> |
56
|
|
|
</testcase> |
57
|
|
|
</testsuite> |
58
|
|
|
', |
59
|
|
|
]; |
60
|
|
|
|
61
|
|
|
yield [ |
62
|
|
|
'Multiple file errors', |
63
|
|
|
1, |
64
|
|
|
4, |
65
|
|
|
0, |
66
|
|
|
'<?xml version="1.0" encoding="UTF-8"?> |
67
|
|
|
<testsuite failures="4" name="phpstan" tests="4" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/junit-team/junit5/r5.5.1/platform-tests/src/test/resources/jenkins-junit.xsd"> |
68
|
|
|
<testcase name="folder with unicode 😃/file name with "spaces" and unicode 😃.php:4"> |
69
|
|
|
<failure message="Foo" /> |
70
|
|
|
</testcase> |
71
|
|
|
<testcase name="foo.php:1"> |
72
|
|
|
<failure message="Foo"/> |
73
|
|
|
</testcase> |
74
|
|
|
<testcase name="foo.php:5"> |
75
|
|
|
<failure message="Bar"/> |
76
|
|
|
</testcase> |
77
|
|
|
<testcase name="folder with unicode 😃/file name with "spaces" and unicode 😃.php:2"> |
78
|
|
|
<failure message="Bar" /> |
79
|
|
|
</testcase> |
80
|
|
|
</testsuite> |
81
|
|
|
', |
82
|
|
|
]; |
83
|
|
|
|
84
|
|
|
yield [ |
85
|
|
|
'Multiple generic errors', |
86
|
|
|
1, |
87
|
|
|
0, |
88
|
|
|
2, |
89
|
|
|
'<?xml version="1.0" encoding="UTF-8"?> |
90
|
|
|
<testsuite failures="2" name="phpstan" tests="2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/junit-team/junit5/r5.5.1/platform-tests/src/test/resources/jenkins-junit.xsd"> |
91
|
|
|
<testcase name="Generic error"> |
92
|
|
|
<failure message="first generic error" /> |
93
|
|
|
</testcase> |
94
|
|
|
<testcase name="Generic error"> |
95
|
|
|
<failure message="second generic error"/> |
96
|
|
|
</testcase> |
97
|
|
|
</testsuite> |
98
|
|
|
', |
99
|
|
|
]; |
100
|
|
|
|
101
|
|
|
yield [ |
102
|
|
|
'Multiple file, multiple generic errors', |
103
|
|
|
1, |
104
|
|
|
4, |
105
|
|
|
2, |
106
|
|
|
'<?xml version="1.0" encoding="UTF-8"?> |
107
|
|
|
<testsuite failures="6" name="phpstan" tests="6" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/junit-team/junit5/r5.5.1/platform-tests/src/test/resources/jenkins-junit.xsd"> |
108
|
|
|
<testcase name="folder with unicode 😃/file name with "spaces" and unicode 😃.php:4"> |
109
|
|
|
<failure message="Foo" /> |
110
|
|
|
</testcase> |
111
|
|
|
<testcase name="foo.php:1"> |
112
|
|
|
<failure message="Foo"/> |
113
|
|
|
</testcase> |
114
|
|
|
<testcase name="foo.php:5"> |
115
|
|
|
<failure message="Bar"/> |
116
|
|
|
</testcase> |
117
|
|
|
<testcase name="folder with unicode 😃/file name with "spaces" and unicode 😃.php:2"> |
118
|
|
|
<failure message="Bar" /> |
119
|
|
|
</testcase> |
120
|
|
|
<testcase name="Generic error"> |
121
|
|
|
<failure message="first generic error" /> |
122
|
|
|
</testcase> |
123
|
|
|
<testcase name="Generic error"> |
124
|
|
|
<failure message="second generic error"/> |
125
|
|
|
</testcase> |
126
|
|
|
</testsuite> |
127
|
|
|
', |
128
|
|
|
]; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
/** |
132
|
|
|
* Test generated use cases for JUnit output format. |
133
|
|
|
* |
134
|
|
|
* @dataProvider dataFormatterOutputProvider |
135
|
|
|
* |
136
|
|
|
* @param string $message |
137
|
|
|
* @param int $exitCode |
138
|
|
|
* @param int $numFileErrors |
139
|
|
|
* @param int $numGenericErrors |
140
|
|
|
* @param string $expected |
141
|
|
|
*/ |
142
|
|
|
public function testFormatErrors( |
143
|
|
|
string $message, |
144
|
|
|
int $exitCode, |
145
|
|
|
int $numFileErrors, |
146
|
|
|
int $numGenericErrors, |
147
|
|
|
string $expected |
148
|
|
|
) { |
149
|
|
|
$formatter = new JunitErrorFormatter(self::DIRECTORY_PATH); |
150
|
|
|
|
151
|
|
|
$this->assertSame($exitCode, $formatter->formatErrors( |
152
|
|
|
$this->getAnalysisResult($numFileErrors, $numGenericErrors), |
153
|
|
|
$this->getErrorConsoleStyle() |
154
|
|
|
), sprintf('%s: response code do not match', $message)); |
155
|
|
|
|
156
|
|
|
$xml = new DOMDocument(); |
157
|
|
|
$xml->loadXML($this->getOutputContent()); |
158
|
|
|
|
159
|
|
|
$this->assertTrue($xml->schemaValidate('https://raw.githubusercontent.com/junit-team/junit5/r5.5.1/platform-tests/src/test/resources/jenkins-junit.xsd')); |
160
|
|
|
|
161
|
|
|
$this->assertXmlStringEqualsXmlString($expected, $this->getOutputContent(), sprintf('%s: XML do not match', $message)); |
162
|
|
|
} |
163
|
|
|
} |
164
|
|
|
|
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.