-
-
Notifications
You must be signed in to change notification settings - Fork 440
Expand file tree
/
Copy pathJsonOutputFormatterTest.php
More file actions
70 lines (59 loc) · 2.23 KB
/
JsonOutputFormatterTest.php
File metadata and controls
70 lines (59 loc) · 2.23 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
<?php
declare(strict_types=1);
namespace ChangesReporting\Output;
use PHPUnit\Framework\TestCase;
use Rector\ChangesReporting\Output\JsonOutputFormatter;
use Rector\ChangesReporting\ValueObject\RectorWithLineChange;
use Rector\Php80\Rector\Identical\StrStartsWithRector;
use Rector\ValueObject\Configuration;
use Rector\ValueObject\Error\SystemError;
use Rector\ValueObject\ProcessResult;
use Rector\ValueObject\Reporting\FileDiff;
final class JsonOutputFormatterTest extends TestCase
{
private readonly JsonOutputFormatter $jsonOutputFormatter;
protected function setUp(): void
{
$this->jsonOutputFormatter = new JsonOutputFormatter();
parent::setUp();
}
public function testGetName(): void
{
$this->assertSame('json', $this->jsonOutputFormatter->getName());
}
public function testReportShouldShowNumberOfChangesWithNoDiffs(): void
{
$this->expectOsOutputString((string) file_get_contents(__DIR__ . '/Fixtures/without_diffs.json'));
$this->jsonOutputFormatter->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)]
),
new FileDiff(
'some/file_foo.php',
'',
'',
[new RectorWithLineChange(StrStartsWithRector::class, 38)]
),
],
2
),
new Configuration(showDiffs: false)
);
}
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);
}
}