Skip to content

Commit 00df8f2

Browse files
committed
Add test
1 parent e6142e4 commit 00df8f2

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---------------------------%s
2+
/data/folder/with space/and unicode 😃/project/folder with unicode 😃/file name with "spaces" and unicode 😃.php:4
3+
---------------------------%s
4+
- '#Foo#'
5+
🪪 identical.alwaysFalse
6+
---------------------------%s
7+
8+
9+
[ERROR] Found 1 errors
10+
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Symplify\PHPStanExtensions\Tests\ErrorFormatter;
6+
7+
use Iterator;
8+
use PHPStan\Analyser\Error;
9+
use PHPStan\Command\AnalysisResult;
10+
use PHPStan\ShouldNotHappenException;
11+
use PHPStan\Testing\ErrorFormatterTestCase;
12+
use PHPUnit\Framework\Attributes\DataProvider;
13+
use Symplify\PHPStanExtensions\ErrorFormatter\SymplifyErrorFormatter;
14+
15+
/**
16+
* @see https://github.com/phpstan/phpstan-src/blob/1.8.x/tests/PHPStan/Command/ErrorFormatter/RawErrorFormatterTest.php
17+
*/
18+
final class SymplifyErrorFormatterVerboseTest extends ErrorFormatterTestCase
19+
{
20+
#[DataProvider('provideData')]
21+
public function testFormatErrors(
22+
string $message,
23+
int $expectedExitCode,
24+
int $numFileErrors,
25+
int $numGenericErrors,
26+
string $expectedOutputFile,
27+
): void {
28+
$symplifyErrorFormatter = self::getContainer()->getByType(SymplifyErrorFormatter::class);
29+
30+
$analysisResult = $this->getAnalysisResult($numFileErrors, $numGenericErrors);
31+
$output = $this->getOutput(verbose: true);
32+
$resultCode = $symplifyErrorFormatter->formatErrors($analysisResult, $output);
33+
34+
$this->assertSame($expectedExitCode, $resultCode);
35+
36+
$this->assertStringMatchesFormatFile($expectedOutputFile, $this->getOutputContent(verbose: true));
37+
}
38+
39+
/**
40+
* @return Iterator<mixed>
41+
*/
42+
public static function provideData(): Iterator
43+
{
44+
yield ['Some message', 1, 1, 1, __DIR__ . '/Fixture/expected_single_message_many_files_report_verbose.txt'];
45+
}
46+
47+
/**
48+
* @return string[]
49+
*/
50+
public static function getAdditionalConfigFiles(): array
51+
{
52+
return [__DIR__ . '/../../config/config.neon'];
53+
}
54+
55+
protected function getAnalysisResult($numFileErrors, int $numGenericErrors): AnalysisResult
56+
{
57+
$fileErrors = [new Error('Foo', self::DIRECTORY_PATH . '/folder with unicode 😃/file name with "spaces" and unicode 😃.php', 4, identifier: 'identical.alwaysFalse')];
58+
59+
return new AnalysisResult($fileErrors, [], [], [], [], \false, null, \true, 0, \false, []);
60+
}
61+
}

0 commit comments

Comments
 (0)