Repository navigation
Expand file tree
/
Copy pathJsonOutputFactoryTest.php
More file actions
77 lines (69 loc) · 2.75 KB
/
Copy pathJsonOutputFactoryTest.php
File metadata and controls
77 lines (69 loc) · 2.75 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
<?php
declare(strict_types=1);
namespace Rector\Tests\ChangesReporting\Output\Factory;
use PHPUnit\Framework\TestCase;
use Rector\ChangesReporting\Output\Factory\JsonOutputFactory;
use Rector\ChangesReporting\ValueObject\RectorWithLineChange;
use Rector\Php80\Rector\Identical\StrEndsWithRector;
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 JsonOutputFactoryTest extends TestCase
{
public function testReportShouldShowNumberOfChangesWithNoDiffs(): void
{
$actualOutput = JsonOutputFactory::create(
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)
);
$expectedOutput = (string) file_get_contents(__DIR__ . '/../Fixtures/without_diffs.json');
$this->assertSame($expectedOutput, $actualOutput);
}
public function testReportShouldAttributeEachRectorToItsLine(): void
{
$diff = '--- Original' . PHP_EOL . '+++ New' . PHP_EOL .
'@@ -38,5 +39,6 @@' . PHP_EOL .
'return true;' . PHP_EOL . '}' . PHP_EOL;
$actualOutput = JsonOutputFactory::create(
new ProcessResult(
[],
[
new FileDiff(
'some/file.php',
$diff,
'diff console formatted',
[
new RectorWithLineChange(StrStartsWithRector::class, 38),
new RectorWithLineChange(StrEndsWithRector::class, 42),
]
),
],
1
),
new Configuration(showDiffs: true)
);
$expectedOutput = (string) file_get_contents(__DIR__ . '/../Fixtures/with_diffs.json');
$this->assertSame($expectedOutput, $actualOutput);
}
}