Skip to content

Commit 0987faa

Browse files
committed
Teamcity - show rule identifier when verbose output is set
1 parent efdd51e commit 0987faa

File tree

2 files changed

+57
-3
lines changed

2 files changed

+57
-3
lines changed

src/Command/ErrorFormatter/TeamcityErrorFormatter.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,15 @@ public function formatErrors(AnalysisResult $analysisResult, Output $output): in
4141
]);
4242

4343
foreach ($fileSpecificErrors as $fileSpecificError) {
44+
$message = $fileSpecificError->getMessage();
45+
46+
if($output->isVerbose() && $fileSpecificError->getIdentifier() !== null) {
47+
$message .= sprintf(' (🪪 %s)', $fileSpecificError->getIdentifier());
48+
}
49+
4450
$result .= $this->createTeamcityLine('inspection', [
4551
'typeId' => 'phpstan',
46-
'message' => $fileSpecificError->getMessage(),
52+
'message' => $message,
4753
'file' => $this->relativePathHelper->getRelativePath($fileSpecificError->getFile()),
4854
'line' => $fileSpecificError->getLine(),
4955
// additional attributes

tests/PHPStan/Command/ErrorFormatter/TeamcityErrorFormatterTest.php

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ public function dataFormatterOutputProvider(): iterable
1818
0,
1919
0,
2020
'',
21+
'',
2122
];
2223

2324
yield [
@@ -27,6 +28,9 @@ public function dataFormatterOutputProvider(): iterable
2728
0,
2829
'##teamcity[inspectionType id=\'phpstan\' name=\'phpstan\' category=\'phpstan\' description=\'phpstan Inspection\']
2930
##teamcity[inspection typeId=\'phpstan\' message=\'Foo\' file=\'folder with unicode 😃/file name with "spaces" and unicode 😃.php\' line=\'4\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
31+
',
32+
'##teamcity[inspectionType id=\'phpstan\' name=\'phpstan\' category=\'phpstan\' description=\'phpstan Inspection\']
33+
##teamcity[inspection typeId=\'phpstan\' message=\'Foo\' file=\'folder with unicode 😃/file name with "spaces" and unicode 😃.php\' line=\'4\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
3034
',
3135
];
3236

@@ -37,6 +41,9 @@ public function dataFormatterOutputProvider(): iterable
3741
1,
3842
'##teamcity[inspectionType id=\'phpstan\' name=\'phpstan\' category=\'phpstan\' description=\'phpstan Inspection\']
3943
##teamcity[inspection typeId=\'phpstan\' message=\'first generic error\' file=\'.\' SEVERITY=\'ERROR\']
44+
',
45+
'##teamcity[inspectionType id=\'phpstan\' name=\'phpstan\' category=\'phpstan\' description=\'phpstan Inspection\']
46+
##teamcity[inspection typeId=\'phpstan\' message=\'first generic error\' file=\'.\' SEVERITY=\'ERROR\']
4047
',
4148
];
4249

@@ -50,6 +57,12 @@ public function dataFormatterOutputProvider(): iterable
5057
##teamcity[inspection typeId=\'phpstan\' message=\'Foo\' file=\'folder with unicode 😃/file name with "spaces" and unicode 😃.php\' line=\'4\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
5158
##teamcity[inspection typeId=\'phpstan\' message=\'Foo<Bar>\' file=\'foo.php\' line=\'1\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
5259
##teamcity[inspection typeId=\'phpstan\' message=\'Bar||nBar2\' file=\'foo.php\' line=\'5\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'a tip\']
60+
',
61+
'##teamcity[inspectionType id=\'phpstan\' name=\'phpstan\' category=\'phpstan\' description=\'phpstan Inspection\']
62+
##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=\'\']
63+
##teamcity[inspection typeId=\'phpstan\' message=\'Foo\' file=\'folder with unicode 😃/file name with "spaces" and unicode 😃.php\' line=\'4\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
64+
##teamcity[inspection typeId=\'phpstan\' message=\'Foo<Bar>\' file=\'foo.php\' line=\'1\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
65+
##teamcity[inspection typeId=\'phpstan\' message=\'Bar||nBar2\' file=\'foo.php\' line=\'5\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'a tip\']
5366
',
5467
];
5568

@@ -61,6 +74,10 @@ public function dataFormatterOutputProvider(): iterable
6174
'##teamcity[inspectionType id=\'phpstan\' name=\'phpstan\' category=\'phpstan\' description=\'phpstan Inspection\']
6275
##teamcity[inspection typeId=\'phpstan\' message=\'first generic error\' file=\'.\' SEVERITY=\'ERROR\']
6376
##teamcity[inspection typeId=\'phpstan\' message=\'second generic<error>\' file=\'.\' SEVERITY=\'ERROR\']
77+
',
78+
'##teamcity[inspectionType id=\'phpstan\' name=\'phpstan\' category=\'phpstan\' description=\'phpstan Inspection\']
79+
##teamcity[inspection typeId=\'phpstan\' message=\'first generic error\' file=\'.\' SEVERITY=\'ERROR\']
80+
##teamcity[inspection typeId=\'phpstan\' message=\'second generic<error>\' file=\'.\' SEVERITY=\'ERROR\']
6481
',
6582
];
6683

@@ -76,20 +93,44 @@ public function dataFormatterOutputProvider(): iterable
7693
##teamcity[inspection typeId=\'phpstan\' message=\'Bar||nBar2\' file=\'foo.php\' line=\'5\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'a tip\']
7794
##teamcity[inspection typeId=\'phpstan\' message=\'first generic error\' file=\'.\' SEVERITY=\'ERROR\']
7895
##teamcity[inspection typeId=\'phpstan\' message=\'second generic<error>\' file=\'.\' SEVERITY=\'ERROR\']
96+
',
97+
'##teamcity[inspectionType id=\'phpstan\' name=\'phpstan\' category=\'phpstan\' description=\'phpstan Inspection\']
98+
##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=\'\']
99+
##teamcity[inspection typeId=\'phpstan\' message=\'Foo\' file=\'folder with unicode 😃/file name with "spaces" and unicode 😃.php\' line=\'4\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
100+
##teamcity[inspection typeId=\'phpstan\' message=\'Foo<Bar>\' file=\'foo.php\' line=\'1\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
101+
##teamcity[inspection typeId=\'phpstan\' message=\'Bar||nBar2\' file=\'foo.php\' line=\'5\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'a tip\']
102+
##teamcity[inspection typeId=\'phpstan\' message=\'first generic error\' file=\'.\' SEVERITY=\'ERROR\']
103+
##teamcity[inspection typeId=\'phpstan\' message=\'second generic<error>\' file=\'.\' SEVERITY=\'ERROR\']
104+
',
105+
];
106+
107+
yield [
108+
'One file error',
109+
1,
110+
[4, 2],
111+
0,
112+
'##teamcity[inspectionType id=\'phpstan\' name=\'phpstan\' category=\'phpstan\' description=\'phpstan Inspection\']
113+
##teamcity[inspection typeId=\'phpstan\' message=\'Bar||nBar2\' file=\'foo.php\' line=\'\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
114+
##teamcity[inspection typeId=\'phpstan\' message=\'Foobar\Buz\' file=\'foo.php\' line=\'5\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'a tip\']
115+
',
116+
'##teamcity[inspectionType id=\'phpstan\' name=\'phpstan\' category=\'phpstan\' description=\'phpstan Inspection\']
117+
##teamcity[inspection typeId=\'phpstan\' message=\'Bar||nBar2\' file=\'foo.php\' line=\'\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\']
118+
##teamcity[inspection typeId=\'phpstan\' message=\'Foobar\Buz (🪪 foobar.buz)\' file=\'foo.php\' line=\'5\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'a tip\']
79119
',
80120
];
81121
}
82122

83123
/**
84124
* @dataProvider dataFormatterOutputProvider
85-
*
125+
* @param array{int, int}|int $numFileErrors
86126
*/
87127
public function testFormatErrors(
88128
string $message,
89129
int $exitCode,
90-
int $numFileErrors,
130+
array|int $numFileErrors,
91131
int $numGenericErrors,
92132
string $expected,
133+
string $expectedVerbose,
93134
): void
94135
{
95136
$relativePathHelper = new FuzzyRelativePathHelper(new NullRelativePathHelper(), self::DIRECTORY_PATH, [], '/');
@@ -103,6 +144,13 @@ public function testFormatErrors(
103144
), sprintf('%s: response code do not match', $message));
104145

105146
$this->assertEquals($expected, $this->getOutputContent(), sprintf('%s: output do not match', $message));
147+
148+
$this->assertSame($exitCode, $formatter->formatErrors(
149+
$this->getAnalysisResult($numFileErrors, $numGenericErrors),
150+
$this->getOutput(false, true),
151+
), sprintf('%s: response code do not match', $message));
152+
153+
$this->assertEquals($expectedVerbose, $this->getOutputContent(false, true), sprintf('%s: output do not match', $message));
106154
}
107155

108156
}

0 commit comments

Comments
 (0)