-
-
Notifications
You must be signed in to change notification settings - Fork 440
Expand file tree
/
Copy pathGitHubOutputFormatterTest.php
More file actions
113 lines (97 loc) · 4.29 KB
/
GitHubOutputFormatterTest.php
File metadata and controls
113 lines (97 loc) · 4.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
declare(strict_types=1);
namespace Rector\Tests\ChangesReporting\Output;
use PHPUnit\Framework\TestCase;
use Rector\ChangesReporting\Output\GitHubOutputFormatter;
use Rector\ChangesReporting\ValueObject\RectorWithLineChange;
use Rector\Php80\Rector\Identical\StrStartsWithRector;
use Rector\Php81\Rector\FuncCall\NullToStrictStringFuncCallArgRector;
use Rector\ValueObject\Configuration;
use Rector\ValueObject\Error\SystemError;
use Rector\ValueObject\ProcessResult;
use Rector\ValueObject\Reporting\FileDiff;
final class GitHubOutputFormatterTest extends TestCase
{
private readonly GitHubOutputFormatter $gitHubOutputFormatter;
protected function setUp(): void
{
$this->gitHubOutputFormatter = new GitHubOutputFormatter();
parent::setUp();
}
public function testGetName(): void
{
$this->assertSame('github', $this->gitHubOutputFormatter->getName());
}
public function testReportShouldOutputErrorMessagesGrouped(): void
{
$this->expectOsOutputString(
'::group::Rector report' . PHP_EOL .
'::error file=some/file.php,line=1::Some error message' . PHP_EOL .
'::error file=some/file.php,line=38::StrStartsWithRector%0A%0A--- Original%0A+++ New%0A@@ -38,5 +39,6 @@%0Areturn true;%0A}%0A' . PHP_EOL .
'::endgroup::' . PHP_EOL
);
$this->gitHubOutputFormatter->report(
new ProcessResult(
[new SystemError('Some error message', 'some/file.php', 1)],
[
new FileDiff(
'some/file.php',
'--- Original' . PHP_EOL . '+++ New' . PHP_EOL .
'@@ -38,5 +39,6 @@' . PHP_EOL .
'return true;' . PHP_EOL . '}' . PHP_EOL,
'diff console formatted',
[new RectorWithLineChange(StrStartsWithRector::class, 38)]
),
],
1
),
new Configuration()
);
}
public function testReportShouldOutputErrorMessagesGroupedWithNoErrors(): void
{
$this->expectOsOutputString('::group::Rector report' . PHP_EOL . '::endgroup::' . PHP_EOL);
$this->gitHubOutputFormatter->report(new ProcessResult([], [], 1), new Configuration());
}
public function testReportShouldOutputErrorMessagesGroupedWithMultipleDiffs(): void
{
$this->expectOsOutputString(
'::group::Rector report' . PHP_EOL .
'::error file=some/file.php,line=38::StrStartsWithRector / NullToStrictStringFuncCallArgRector%0A%0A--- Original%0A+++ New%0A@@ -38,5 +39,6 @@%0Areturn true;%0A}%0A' . PHP_EOL .
'::error file=some/another-file.php,line=54::StrStartsWithRector%0A%0A--- Original%0A+++ New%0A@@ -54,10 +54,10 @@%0Areturn true;%0A}%0A' . PHP_EOL .
'::endgroup::' . PHP_EOL
);
$this->gitHubOutputFormatter->report(
new ProcessResult([], [
new FileDiff(
'some/file.php',
'--- Original' . PHP_EOL . '+++ New' . PHP_EOL .
'@@ -38,5 +39,6 @@' . PHP_EOL .
'return true;' . PHP_EOL . '}' . PHP_EOL,
'diff console formatted',
[
new RectorWithLineChange(StrStartsWithRector::class, 38),
new RectorWithLineChange(NullToStrictStringFuncCallArgRector::class, 38),
]
),
new FileDiff(
'some/another-file.php',
'--- Original' . PHP_EOL . '+++ New' . PHP_EOL .
'@@ -54,10 +54,10 @@' . PHP_EOL .
'return true;' . PHP_EOL . '}' . PHP_EOL,
'diff console formatted',
[new RectorWithLineChange(StrStartsWithRector::class, 54)]
),
], 2),
new Configuration()
);
}
protected function expectOsOutputString(string $expectedOutput): void
{
$isWindows = strncasecmp(PHP_OS, 'WIN', 3) === 0;
if ($isWindows) {
$expectedOutput = str_replace('%0A', '%0D%0A', $expectedOutput);
}
parent::expectOutputString($expectedOutput);
}
}