From 67d9dd8b02bdba48f86729de8974039be31f7f2f Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sat, 17 Sep 2022 11:09:57 +0200 Subject: [PATCH 1/2] add tip-message to json error format --- src/Command/ErrorFormatter/JsonErrorFormatter.php | 8 +++++++- src/Testing/ErrorFormatterTestCase.php | 2 +- .../Command/ErrorFormatter/JsonErrorFormatterTest.php | 6 ++++-- .../Command/ErrorFormatter/TeamcityErrorFormatterTest.php | 4 ++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/Command/ErrorFormatter/JsonErrorFormatter.php b/src/Command/ErrorFormatter/JsonErrorFormatter.php index 4c075f0ac7..5139a87554 100644 --- a/src/Command/ErrorFormatter/JsonErrorFormatter.php +++ b/src/Command/ErrorFormatter/JsonErrorFormatter.php @@ -36,11 +36,17 @@ public function formatErrors(AnalysisResult $analysisResult, Output $output): in } $errorsArray['files'][$file]['errors']++; - $errorsArray['files'][$file]['messages'][] = [ + $message = [ 'message' => $fileSpecificError->getMessage(), 'line' => $fileSpecificError->getLine(), 'ignorable' => $fileSpecificError->canBeIgnored(), ]; + + if ($fileSpecificError->getTip() !== null) { + $message['tip'] = $fileSpecificError->getTip(); + } + + $errorsArray['files'][$file]['messages'][] = $message; } foreach ($analysisResult->getNotFileSpecificErrors() as $notFileSpecificError) { diff --git a/src/Testing/ErrorFormatterTestCase.php b/src/Testing/ErrorFormatterTestCase.php index be335517a9..4813452b71 100644 --- a/src/Testing/ErrorFormatterTestCase.php +++ b/src/Testing/ErrorFormatterTestCase.php @@ -81,7 +81,7 @@ 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("Bar\nBar2", self::DIRECTORY_PATH . '/foo.php', 5), + 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); diff --git a/tests/PHPStan/Command/ErrorFormatter/JsonErrorFormatterTest.php b/tests/PHPStan/Command/ErrorFormatter/JsonErrorFormatterTest.php index d76c8c15b8..17a687af4c 100644 --- a/tests/PHPStan/Command/ErrorFormatter/JsonErrorFormatterTest.php +++ b/tests/PHPStan/Command/ErrorFormatter/JsonErrorFormatterTest.php @@ -109,7 +109,8 @@ public function dataFormatterOutputProvider(): iterable { "message": "Bar\nBar2", "line": 5, - "ignorable": true + "ignorable": true, + "tip": "a tip" } ] } @@ -175,7 +176,8 @@ public function dataFormatterOutputProvider(): iterable { "message": "Bar\nBar2", "line": 5, - "ignorable": true + "ignorable": true, + "tip": "a tip" } ] } diff --git a/tests/PHPStan/Command/ErrorFormatter/TeamcityErrorFormatterTest.php b/tests/PHPStan/Command/ErrorFormatter/TeamcityErrorFormatterTest.php index 37e7e3451c..c0932ac1d1 100644 --- a/tests/PHPStan/Command/ErrorFormatter/TeamcityErrorFormatterTest.php +++ b/tests/PHPStan/Command/ErrorFormatter/TeamcityErrorFormatterTest.php @@ -49,7 +49,7 @@ public function dataFormatterOutputProvider(): iterable ##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=\'Bar||nBar2\' file=\'foo.php\' line=\'5\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'\'] +##teamcity[inspection typeId=\'phpstan\' message=\'Bar||nBar2\' file=\'foo.php\' line=\'5\' SEVERITY=\'ERROR\' ignorable=\'1\' tip=\'a tip\'] ', ]; @@ -73,7 +73,7 @@ public function dataFormatterOutputProvider(): iterable ##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=\'Bar||nBar2\' file=\'foo.php\' line=\'5\' 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\'] ', From 743c6303e279630099db8494f7a1726121bf9a3a Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sat, 17 Sep 2022 11:19:47 +0200 Subject: [PATCH 2/2] fix tests --- src/Testing/LevelsTestCase.php | 4 ++++ .../ErrorFormatter/TableErrorFormatterTest.php | 14 ++++++++------ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/Testing/LevelsTestCase.php b/src/Testing/LevelsTestCase.php index 0204461a34..277c9db9f4 100644 --- a/src/Testing/LevelsTestCase.php +++ b/src/Testing/LevelsTestCase.php @@ -110,6 +110,8 @@ public function testLevels( } } + unset($message['tip']); + $messages[] = $message; } @@ -124,6 +126,8 @@ public function testLevels( } } + unset($previousMessage['tip']); + $missingMessages[] = $previousMessage; } diff --git a/tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php b/tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php index 28ae7cd621..f83f2de850 100644 --- a/tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php +++ b/tests/PHPStan/Command/ErrorFormatter/TableErrorFormatterTest.php @@ -85,13 +85,14 @@ public function dataFormatterOutputProvider(): iterable 4 Foo ------ ------------------------------------------------------------------- - ------ --------- + ------ ---------- Line foo.php - ------ --------- + ------ ---------- 1 Foo 5 Bar Bar2 - ------ --------- + 💡 a tip + ------ ---------- [ERROR] Found 4 errors @@ -129,13 +130,14 @@ public function dataFormatterOutputProvider(): iterable 4 Foo ------ ------------------------------------------------------------------- - ------ --------- + ------ ---------- Line foo.php - ------ --------- + ------ ---------- 1 Foo 5 Bar Bar2 - ------ --------- + 💡 a tip + ------ ---------- -- ---------------------- Error