|
| 1 | +<?php declare(strict_types = 1); |
| 2 | + |
| 3 | +namespace PHPStan\Command\ErrorFormatter; |
| 4 | + |
| 5 | +use PHPStan\File\FuzzyRelativePathHelper; |
| 6 | +use PHPStan\Testing\ErrorFormatterTestCase; |
| 7 | + |
| 8 | +class GithubErrorFormatterTest extends ErrorFormatterTestCase |
| 9 | +{ |
| 10 | + |
| 11 | + public function dataFormatterOutputProvider(): iterable |
| 12 | + { |
| 13 | + yield [ |
| 14 | + 'No errors', |
| 15 | + 0, |
| 16 | + 0, |
| 17 | + 0, |
| 18 | + ' |
| 19 | + [OK] No errors |
| 20 | +
|
| 21 | +', |
| 22 | + ]; |
| 23 | + |
| 24 | + yield [ |
| 25 | + 'One file error', |
| 26 | + 1, |
| 27 | + 1, |
| 28 | + 0, |
| 29 | + ' ------ ----------------------------------------------------------------- |
| 30 | + Line folder with unicode 😃/file name with "spaces" and unicode 😃.php |
| 31 | + ------ ----------------------------------------------------------------- |
| 32 | + 4 Foo |
| 33 | + ------ ----------------------------------------------------------------- |
| 34 | +
|
| 35 | + [ERROR] Found 1 error |
| 36 | +
|
| 37 | +::error file=folder with unicode 😃/file name with "spaces" and unicode 😃.php,line=4,col=0::Foo |
| 38 | +', |
| 39 | + ]; |
| 40 | + |
| 41 | + yield [ |
| 42 | + 'One generic error', |
| 43 | + 1, |
| 44 | + 0, |
| 45 | + 1, |
| 46 | + ' -- --------------------- |
| 47 | + Error |
| 48 | + -- --------------------- |
| 49 | + first generic error |
| 50 | + -- --------------------- |
| 51 | +
|
| 52 | + [ERROR] Found 1 error |
| 53 | +
|
| 54 | +', |
| 55 | + ]; |
| 56 | + |
| 57 | + yield [ |
| 58 | + 'Multiple file errors', |
| 59 | + 1, |
| 60 | + 4, |
| 61 | + 0, |
| 62 | + ' ------ ----------------------------------------------------------------- |
| 63 | + Line folder with unicode 😃/file name with "spaces" and unicode 😃.php |
| 64 | + ------ ----------------------------------------------------------------- |
| 65 | + 2 Bar |
| 66 | + 4 Foo |
| 67 | + ------ ----------------------------------------------------------------- |
| 68 | +
|
| 69 | + ------ --------- |
| 70 | + Line foo.php |
| 71 | + ------ --------- |
| 72 | + 1 Foo |
| 73 | + 5 Bar |
| 74 | + ------ --------- |
| 75 | +
|
| 76 | + [ERROR] Found 4 errors |
| 77 | +
|
| 78 | +::error file=folder with unicode 😃/file name with "spaces" and unicode 😃.php,line=2,col=0::Bar |
| 79 | +::error file=folder with unicode 😃/file name with "spaces" and unicode 😃.php,line=4,col=0::Foo |
| 80 | +::error file=foo.php,line=1,col=0::Foo |
| 81 | +::error file=foo.php,line=5,col=0::Bar |
| 82 | +', |
| 83 | + ]; |
| 84 | + |
| 85 | + yield [ |
| 86 | + 'Multiple generic errors', |
| 87 | + 1, |
| 88 | + 0, |
| 89 | + 2, |
| 90 | + ' -- ---------------------- |
| 91 | + Error |
| 92 | + -- ---------------------- |
| 93 | + first generic error |
| 94 | + second generic error |
| 95 | + -- ---------------------- |
| 96 | +
|
| 97 | + [ERROR] Found 2 errors |
| 98 | +
|
| 99 | +', |
| 100 | + ]; |
| 101 | + |
| 102 | + yield [ |
| 103 | + 'Multiple file, multiple generic errors', |
| 104 | + 1, |
| 105 | + 4, |
| 106 | + 2, |
| 107 | + ' ------ ----------------------------------------------------------------- |
| 108 | + Line folder with unicode 😃/file name with "spaces" and unicode 😃.php |
| 109 | + ------ ----------------------------------------------------------------- |
| 110 | + 2 Bar |
| 111 | + 4 Foo |
| 112 | + ------ ----------------------------------------------------------------- |
| 113 | +
|
| 114 | + ------ --------- |
| 115 | + Line foo.php |
| 116 | + ------ --------- |
| 117 | + 1 Foo |
| 118 | + 5 Bar |
| 119 | + ------ --------- |
| 120 | +
|
| 121 | + -- ---------------------- |
| 122 | + Error |
| 123 | + -- ---------------------- |
| 124 | + first generic error |
| 125 | + second generic error |
| 126 | + -- ---------------------- |
| 127 | +
|
| 128 | + [ERROR] Found 6 errors |
| 129 | +
|
| 130 | +::error file=folder with unicode 😃/file name with "spaces" and unicode 😃.php,line=2,col=0::Bar |
| 131 | +::error file=folder with unicode 😃/file name with "spaces" and unicode 😃.php,line=4,col=0::Foo |
| 132 | +::error file=foo.php,line=1,col=0::Foo |
| 133 | +::error file=foo.php,line=5,col=0::Bar |
| 134 | +', |
| 135 | + ]; |
| 136 | + } |
| 137 | + |
| 138 | + /** |
| 139 | + * @dataProvider dataFormatterOutputProvider |
| 140 | + * |
| 141 | + * @param string $message |
| 142 | + * @param int $exitCode |
| 143 | + * @param int $numFileErrors |
| 144 | + * @param int $numGenericErrors |
| 145 | + * @param string $expected |
| 146 | + */ |
| 147 | + public function testFormatErrors( |
| 148 | + string $message, |
| 149 | + int $exitCode, |
| 150 | + int $numFileErrors, |
| 151 | + int $numGenericErrors, |
| 152 | + string $expected |
| 153 | + ): void |
| 154 | + { |
| 155 | + $relativePathHelper = new FuzzyRelativePathHelper(self::DIRECTORY_PATH, [], '/'); |
| 156 | + $formatter = new GithubErrorFormatter( |
| 157 | + $relativePathHelper, |
| 158 | + new TableErrorFormatter($relativePathHelper, false) |
| 159 | + ); |
| 160 | + |
| 161 | + $this->assertSame($exitCode, $formatter->formatErrors( |
| 162 | + $this->getAnalysisResult($numFileErrors, $numGenericErrors), |
| 163 | + $this->getOutput() |
| 164 | + ), sprintf('%s: response code do not match', $message)); |
| 165 | + |
| 166 | + $this->assertEquals($expected, $this->getOutputContent(), sprintf('%s: output do not match', $message)); |
| 167 | + } |
| 168 | + |
| 169 | +} |
0 commit comments