Skip to content

Commit

Permalink
write tests for the JUnit escaping errors
Browse files Browse the repository at this point in the history
  • Loading branch information
mousetail committed May 21, 2024
1 parent fd9dc5e commit 2c75de3
Show file tree
Hide file tree
Showing 10 changed files with 42 additions and 42 deletions.
4 changes: 2 additions & 2 deletions src/Testing/ErrorFormatterTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,15 @@ protected function getAnalysisResult(int $numFileErrors, int $numGenericErrors):

$fileErrors = array_slice([
new Error('Foo', self::DIRECTORY_PATH . '/folder with unicode 😃/file name with "spaces" and unicode 😃.php', 4),
new Error('Foo', self::DIRECTORY_PATH . '/foo.php', 1),
new Error('Foo<Bar>', self::DIRECTORY_PATH . '/foo.php', 1),
new Error("Bar\nBar2", self::DIRECTORY_PATH . '/foo.php', 5, true, null, null, 'a tip'),
new Error("Bar\nBar2", self::DIRECTORY_PATH . '/folder with unicode 😃/file name with "spaces" and unicode 😃.php', 2),
new Error("Bar\nBar2", self::DIRECTORY_PATH . '/foo.php', null),
], 0, $numFileErrors);

$genericErrors = array_slice([
'first generic error',
'second generic error',
'second generic<error>',
], 0, $numGenericErrors);

return new AnalysisResult(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function dataFormatterOutputProvider(): iterable
'path' => 'foo.php',
],
[
'message' => '#^Foo$#',
'message' => '#^Foo\<Bar\>$#',
'count' => 1,
'path' => 'foo.php',
],
Expand Down Expand Up @@ -103,7 +103,7 @@ public function dataFormatterOutputProvider(): iterable
'path' => 'foo.php',
],
[
'message' => '#^Foo$#',
'message' => '#^Foo\<Bar\>$#',
'count' => 1,
'path' => 'foo.php',
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public function dataFormatterOutputProvider(): iterable
<error line="4" column="1" severity="error" message="Foo"/>
</file>
<file name="foo.php">
<error line="1" column="1" severity="error" message="Foo"/>
<error line="1" column="1" severity="error" message="Foo&lt;Bar&gt;"/>
<error line="5" column="1" severity="error" message="Bar Bar2"/>
</file>
</checkstyle>
Expand All @@ -80,7 +80,7 @@ public function dataFormatterOutputProvider(): iterable
<checkstyle>
<file>
<error message="first generic error" severity="error"/>
<error message="second generic error" severity="error"/>
<error message="second generic&lt;error&gt;" severity="error"/>
</file>
</checkstyle>
',
Expand All @@ -98,12 +98,12 @@ public function dataFormatterOutputProvider(): iterable
<error line="4" column="1" severity="error" message="Foo"/>
</file>
<file name="foo.php">
<error line="1" column="1" severity="error" message="Foo"/>
<error line="1" column="1" severity="error" message="Foo&lt;Bar&gt;"/>
<error line="5" column="1" severity="error" message="Bar Bar2"/>
</file>
<file>
<error message="first generic error" severity="error"/>
<error message="second generic error" severity="error"/>
<error message="second generic&lt;error&gt;" severity="error"/>
</file>
</checkstyle>
',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function dataFormatterOutputProvider(): iterable
0,
'::error file=folder with unicode 😃/file name with "spaces" and unicode 😃.php,line=2,col=0::Bar%0ABar2
::error file=folder with unicode 😃/file name with "spaces" and unicode 😃.php,line=4,col=0::Foo
::error file=foo.php,line=1,col=0::Foo
::error file=foo.php,line=1,col=0::Foo<Bar>
::error file=foo.php,line=5,col=0::Bar%0ABar2
',
];
Expand All @@ -56,7 +56,7 @@ public function dataFormatterOutputProvider(): iterable
0,
2,
'::error ::first generic error
::error ::second generic error
::error ::second generic<error>
',
];

Expand All @@ -67,10 +67,10 @@ public function dataFormatterOutputProvider(): iterable
2,
'::error file=folder with unicode 😃/file name with "spaces" and unicode 😃.php,line=2,col=0::Bar%0ABar2
::error file=folder with unicode 😃/file name with "spaces" and unicode 😃.php,line=4,col=0::Foo
::error file=foo.php,line=1,col=0::Foo
::error file=foo.php,line=1,col=0::Foo<Bar>
::error file=foo.php,line=5,col=0::Bar%0ABar2
::error ::first generic error
::error ::second generic error
::error ::second generic<error>
',
];
}
Expand Down
20 changes: 10 additions & 10 deletions tests/PHPStan/Command/ErrorFormatter/GitlabFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ public function dataFormatterOutputProvider(): iterable
}
},
{
"description": "Foo",
"fingerprint": "93c79740ed8c6fbaac2087e54d6f6f67fc0918e3ff77840530f32e19857ef63c",
"description": "Foo<Bar>",
"fingerprint": "d7002959fc192c81d51fc41b0a3f240617a1aa35361867b5e924ae8d7fec39cb",
"severity": "major",
"location": {
"path": "with space/and unicode \ud83d\ude03/project/foo.php",
Expand Down Expand Up @@ -152,8 +152,8 @@ public function dataFormatterOutputProvider(): iterable
}
},
{
"description": "Foo",
"fingerprint": "93c79740ed8c6fbaac2087e54d6f6f67fc0918e3ff77840530f32e19857ef63c",
"description": "Foo<Bar>",
"fingerprint": "d7002959fc192c81d51fc41b0a3f240617a1aa35361867b5e924ae8d7fec39cb",
"severity": "major",
"location": {
"path": "with space/and unicode \ud83d\ude03/project/foo.php",
Expand Down Expand Up @@ -194,8 +194,8 @@ public function dataFormatterOutputProvider(): iterable
}
},
{
"description": "second generic error",
"fingerprint": "f49870714e8ce889212aefb50f718f88ae63d00dd01c775b7bac86c4466e96f0",
"description": "second generic<error>",
"fingerprint": "adc18b2c27b0ecad40aed7975b165cbe357f0cbba58582af91c0a2e7fa5d77ab",
"severity": "major",
"location": {
"path": "",
Expand Down Expand Up @@ -236,8 +236,8 @@ public function dataFormatterOutputProvider(): iterable
}
},
{
"description": "Foo",
"fingerprint": "93c79740ed8c6fbaac2087e54d6f6f67fc0918e3ff77840530f32e19857ef63c",
"description": "Foo<Bar>",
"fingerprint": "d7002959fc192c81d51fc41b0a3f240617a1aa35361867b5e924ae8d7fec39cb",
"severity": "major",
"location": {
"path": "with space/and unicode \ud83d\ude03/project/foo.php",
Expand Down Expand Up @@ -269,8 +269,8 @@ public function dataFormatterOutputProvider(): iterable
}
},
{
"description": "second generic error",
"fingerprint": "f49870714e8ce889212aefb50f718f88ae63d00dd01c775b7bac86c4466e96f0",
"description": "second generic<error>",
"fingerprint": "adc18b2c27b0ecad40aed7975b165cbe357f0cbba58582af91c0a2e7fa5d77ab",
"severity": "major",
"location": {
"path": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public function dataFormatterOutputProvider(): iterable
"errors":2,
"messages":[
{
"message": "Foo",
"message": "Foo<Bar>",
"line": 1,
"ignorable": true
},
Expand Down Expand Up @@ -136,7 +136,7 @@ public function dataFormatterOutputProvider(): iterable
"files":[],
"errors": [
"first generic error",
"second generic error"
"second generic<error>"
]
}',
];
Expand Down Expand Up @@ -172,7 +172,7 @@ public function dataFormatterOutputProvider(): iterable
"errors":2,
"messages":[
{
"message": "Foo",
"message": "Foo<Bar>",
"line": 1,
"ignorable": true
},
Expand All @@ -187,7 +187,7 @@ public function dataFormatterOutputProvider(): iterable
},
"errors": [
"first generic error",
"second generic error"
"second generic<error>"
]
}',
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function dataFormatterOutputProvider(): Generator
<failure type="ERROR" message="Foo" />
</testcase>
<testcase name="foo.php:1">
<failure type="ERROR" message="Foo"/>
<failure type="ERROR" message="Foo&lt;Bar&gt;"/>
</testcase>
<testcase name="foo.php:5">
<failure type="ERROR" message="Bar Bar2"/>
Expand All @@ -93,7 +93,7 @@ public function dataFormatterOutputProvider(): Generator
<failure type="ERROR" message="first generic error" />
</testcase>
<testcase name="General error">
<failure type="ERROR" message="second generic error"/>
<failure type="ERROR" message="second generic&lt;error&gt;"/>
</testcase>
</testsuite>
',
Expand All @@ -112,7 +112,7 @@ public function dataFormatterOutputProvider(): Generator
<failure type="ERROR" message="Foo" />
</testcase>
<testcase name="foo.php:1">
<failure type="ERROR" message="Foo"/>
<failure type="ERROR" message="Foo&lt;Bar&gt;"/>
</testcase>
<testcase name="foo.php:5">
<failure type="ERROR" message="Bar Bar2"/>
Expand All @@ -121,7 +121,7 @@ public function dataFormatterOutputProvider(): Generator
<failure type="ERROR" message="first generic error" />
</testcase>
<testcase name="General error">
<failure type="ERROR" message="second generic error"/>
<failure type="ERROR" message="second generic&lt;error&gt;"/>
</testcase>
</testsuite>
',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function dataFormatterOutputProvider(): iterable
0,
'/data/folder/with space/and unicode 😃/project/folder with unicode 😃/file name with "spaces" and unicode 😃.php:2:Bar' . "\nBar2\n" .
'/data/folder/with space/and unicode 😃/project/folder with unicode 😃/file name with "spaces" and unicode 😃.php:4:Foo' . "\n" .
'/data/folder/with space/and unicode 😃/project/foo.php:1:Foo' . "\n" .
'/data/folder/with space/and unicode 😃/project/foo.php:1:Foo<Bar>' . "\n" .
'/data/folder/with space/and unicode 😃/project/foo.php:5:Bar' . "\nBar2\n",
];

Expand All @@ -51,7 +51,7 @@ public function dataFormatterOutputProvider(): iterable
0,
2,
'?:?:first generic error' . "\n" .
'?:?:second generic error' . "\n",
'?:?:second generic<error>' . "\n",
];

yield [
Expand All @@ -60,10 +60,10 @@ public function dataFormatterOutputProvider(): iterable
4,
2,
'?:?:first generic error' . "\n" .
'?:?:second generic error' . "\n" .
'?:?:second generic<error>' . "\n" .
'/data/folder/with space/and unicode 😃/project/folder with unicode 😃/file name with "spaces" and unicode 😃.php:2:Bar' . "\nBar2\n" .
'/data/folder/with space/and unicode 😃/project/folder with unicode 😃/file name with "spaces" and unicode 😃.php:4:Foo' . "\n" .
'/data/folder/with space/and unicode 😃/project/foo.php:1:Foo' . "\n" .
'/data/folder/with space/and unicode 😃/project/foo.php:1:Foo<Bar>' . "\n" .
'/data/folder/with space/and unicode 😃/project/foo.php:5:Bar' . "\nBar2\n",
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function dataFormatterOutputProvider(): iterable
------ ----------
Line foo.php
------ ----------
1 Foo
1 Foo<Bar>
5 Bar
Bar2
💡 a tip
Expand All @@ -115,7 +115,7 @@ public function dataFormatterOutputProvider(): iterable
Error
-- ----------------------
first generic error
second generic error
second generic<error>
-- ----------------------
Expand All @@ -141,7 +141,7 @@ public function dataFormatterOutputProvider(): iterable
------ ----------
Line foo.php
------ ----------
1 Foo
1 Foo<Bar>
5 Bar
Bar2
💡 a tip
Expand All @@ -151,7 +151,7 @@ public function dataFormatterOutputProvider(): iterable
Error
-- ----------------------
first generic error
second generic error
second generic<error>
-- ----------------------
[ERROR] Found 6 errors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function dataFormatterOutputProvider(): iterable
'##teamcity[inspectionType id=\'phpstan\' name=\'phpstan\' category=\'phpstan\' description=\'phpstan Inspection\']
##teamcity[inspection typeId=\'phpstan\' message=\'Bar||nBar2\' file=\'folder with unicode 😃/file name with "spaces" and unicode 😃.php\' line=\'2\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
##teamcity[inspection typeId=\'phpstan\' message=\'Foo\' file=\'folder with unicode 😃/file name with "spaces" and unicode 😃.php\' line=\'4\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
##teamcity[inspection typeId=\'phpstan\' message=\'Foo\' file=\'foo.php\' line=\'1\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
##teamcity[inspection typeId=\'phpstan\' message=\'Foo<Bar>\' file=\'foo.php\' line=\'1\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
##teamcity[inspection typeId=\'phpstan\' message=\'Bar||nBar2\' file=\'foo.php\' line=\'5\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'a tip\']
',
];
Expand All @@ -60,7 +60,7 @@ public function dataFormatterOutputProvider(): iterable
2,
'##teamcity[inspectionType id=\'phpstan\' name=\'phpstan\' category=\'phpstan\' description=\'phpstan Inspection\']
##teamcity[inspection typeId=\'phpstan\' message=\'first generic error\' file=\'.\' SEVERITY=\'ERROR\']
##teamcity[inspection typeId=\'phpstan\' message=\'second generic error\' file=\'.\' SEVERITY=\'ERROR\']
##teamcity[inspection typeId=\'phpstan\' message=\'second generic<error>\' file=\'.\' SEVERITY=\'ERROR\']
',
];

Expand All @@ -72,10 +72,10 @@ public function dataFormatterOutputProvider(): iterable
'##teamcity[inspectionType id=\'phpstan\' name=\'phpstan\' category=\'phpstan\' description=\'phpstan Inspection\']
##teamcity[inspection typeId=\'phpstan\' message=\'Bar||nBar2\' file=\'folder with unicode 😃/file name with "spaces" and unicode 😃.php\' line=\'2\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
##teamcity[inspection typeId=\'phpstan\' message=\'Foo\' file=\'folder with unicode 😃/file name with "spaces" and unicode 😃.php\' line=\'4\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
##teamcity[inspection typeId=\'phpstan\' message=\'Foo\' file=\'foo.php\' line=\'1\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
##teamcity[inspection typeId=\'phpstan\' message=\'Foo<Bar>\' file=\'foo.php\' line=\'1\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
##teamcity[inspection typeId=\'phpstan\' message=\'Bar||nBar2\' file=\'foo.php\' line=\'5\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'a tip\']
##teamcity[inspection typeId=\'phpstan\' message=\'first generic error\' file=\'.\' SEVERITY=\'ERROR\']
##teamcity[inspection typeId=\'phpstan\' message=\'second generic error\' file=\'.\' SEVERITY=\'ERROR\']
##teamcity[inspection typeId=\'phpstan\' message=\'second generic<error>\' file=\'.\' SEVERITY=\'ERROR\']
',
];
}
Expand Down

0 comments on commit 2c75de3

Please sign in to comment.