Repository navigation
Expand file tree
/
Copy pathJunitErrorFormatterTest.php
More file actions
171 lines (154 loc) · 5.58 KB
/
Copy pathJunitErrorFormatterTest.php
File metadata and controls
171 lines (154 loc) · 5.58 KB
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
<?php declare(strict_types = 1);
namespace PHPStan\Command\ErrorFormatter;
use DOMDocument;
use Generator;
use Override;
use PHPStan\File\SimpleRelativePathHelper;
use PHPStan\Testing\ErrorFormatterTestCase;
use PHPUnit\Framework\Attributes\DataProvider;
class JunitErrorFormatterTest extends ErrorFormatterTestCase
{
private JunitErrorFormatter $formatter;
#[Override]
public function setUp(): void
{
parent::setUp();
$this->formatter = new JunitErrorFormatter(new SimpleRelativePathHelper(self::DIRECTORY_PATH));
}
/**
* @return Generator<array<int, (string|int)>>
*/
public static function dataFormatterOutputProvider(): Generator
{
yield 'No errors' => [
0,
0,
0,
'<?xml version="1.0" encoding="UTF-8"?>
<testsuite failures="0" name="phpstan" tests="1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://raw.githubusercontent.com/junit-team/junit5/r5.9.3/platform-tests/src/test/resources/jenkins-junit.xsd">
<testcase classname="phpstan:0" name=""/>
</testsuite>
',
];
yield 'One file error' => [
1,
1,
0,
'<?xml version="1.0" encoding="UTF-8"?>
<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.9.3/platform-tests/src/test/resources/jenkins-junit.xsd">
<testcase classname="folder with unicode 😃/file name with "spaces" and unicode 😃.php:4" name="">
<failure type="ERROR" message="Foo" />
</testcase>
</testsuite>
',
];
yield 'One generic error' => [
1,
0,
1,
'<?xml version="1.0" encoding="UTF-8"?>
<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.9.3/platform-tests/src/test/resources/jenkins-junit.xsd">
<testcase classname="General error:0" name="">
<failure type="ERROR" message="first generic error" />
</testcase>
</testsuite>
',
];
yield 'Multiple file errors' => [
1,
4,
0,
'<?xml version="1.0" encoding="UTF-8"?>
<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.9.3/platform-tests/src/test/resources/jenkins-junit.xsd">
<testcase classname="folder with unicode 😃/file name with "spaces" and unicode 😃.php:2" name="">
<failure type="ERROR" message="Bar Bar2" />
</testcase>
<testcase classname="folder with unicode 😃/file name with "spaces" and unicode 😃.php:4" name="">
<failure type="ERROR" message="Foo" />
</testcase>
<testcase classname="foo.php:1" name="">
<failure type="ERROR" message="Foo<Bar>"/>
</testcase>
<testcase classname="foo.php:5" name="">
<failure type="ERROR" message="Bar Bar2 a tip"/>
</testcase>
</testsuite>
',
];
yield 'Multiple generic errors' => [
1,
0,
2,
'<?xml version="1.0" encoding="UTF-8"?>
<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.9.3/platform-tests/src/test/resources/jenkins-junit.xsd">
<testcase classname="General error:0" name="">
<failure type="ERROR" message="first generic error" />
</testcase>
<testcase classname="General error:0" name="">
<failure type="ERROR" message="second generic<error>"/>
</testcase>
</testsuite>
',
];
yield 'Multiple file, multiple generic errors' => [
1,
4,
2,
'<?xml version="1.0" encoding="UTF-8"?>
<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.9.3/platform-tests/src/test/resources/jenkins-junit.xsd">
<testcase classname="folder with unicode 😃/file name with "spaces" and unicode 😃.php:2" name="">
<failure type="ERROR" message="Bar Bar2" />
</testcase>
<testcase classname="folder with unicode 😃/file name with "spaces" and unicode 😃.php:4" name="">
<failure type="ERROR" message="Foo" />
</testcase>
<testcase classname="foo.php:1" name="">
<failure type="ERROR" message="Foo<Bar>"/>
</testcase>
<testcase classname="foo.php:5" name="">
<failure type="ERROR" message="Bar Bar2 a tip"/>
</testcase>
<testcase classname="General error:0" name="">
<failure type="ERROR" message="first generic error" />
</testcase>
<testcase classname="General error:0" name="">
<failure type="ERROR" message="second generic<error>"/>
</testcase>
</testsuite>
',
];
}
/**
* Test generated use cases for JUnit output format.
*/
#[DataProvider('dataFormatterOutputProvider')]
public function testFormatErrors(
int $exitCode,
int $numFileErrors,
int $numGeneralErrors,
string $expected,
): void
{
$this->assertSame(
$exitCode,
$this->formatter->formatErrors(
$this->getAnalysisResult($numFileErrors, $numGeneralErrors),
$this->getOutput(),
),
'Response code do not match',
);
$xml = new DOMDocument();
$outputContent = $this->getOutputContent();
$this->assertNotSame('', $outputContent);
$xml->loadXML($outputContent);
$this->assertTrue(
$xml->schemaValidate(__DIR__ . '/junit-schema.xsd'),
'Schema do not validate',
);
$this->assertXmlStringEqualsXmlString(
$expected,
$this->getOutputContent(),
'XML do not match',
);
}
}