Repository navigation
Expand file tree
/
Copy pathMissConfigurationReporterTest.php
More file actions
135 lines (105 loc) · 5.2 KB
/
Copy pathMissConfigurationReporterTest.php
File metadata and controls
135 lines (105 loc) · 5.2 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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
declare(strict_types=1);
namespace Rector\Tests\Reporting;
use Rector\Configuration\Option;
use Rector\Configuration\Parameter\SimpleParameterProvider;
use Rector\Configuration\VendorMissAnalyseGuard;
use Rector\Php85\Rector\FuncCall\OrdSingleByteRector;
use Rector\PostRector\Rector\NameImportingPostRector;
use Rector\Reporting\MissConfigurationReporter;
use Rector\Reporting\UnusedSkipResolver;
use Rector\Testing\PHPUnit\AbstractLazyTestCase;
use Rector\Tests\Skipper\Skipper\Fixture\Element\FifthElement;
use Rector\Tests\Skipper\Skipper\Fixture\Element\ThreeMan;
use Rector\Tests\Skipper\Skipper\Source\AnotherClassToSkip;
use Rector\Validation\RectorConfigValidator;
use Rector\ValueObject\ProcessResult;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Style\SymfonyStyle;
final class MissConfigurationReporterTest extends AbstractLazyTestCase
{
private const string UNUSED_RULE_MASK = '*/dead-rule/*';
private const string USED_RULE_MASK = '*/matched-rule/*';
private const string GLOBAL_MASK = '*/global-mask/*';
private BufferedOutput $bufferedOutput;
private MissConfigurationReporter $missConfigurationReporter;
protected function setUp(): void
{
parent::setUp();
$this->bufferedOutput = new BufferedOutput();
$symfonyStyle = new SymfonyStyle(new ArrayInput([]), $this->bufferedOutput);
$this->missConfigurationReporter = new MissConfigurationReporter(
$symfonyStyle,
new VendorMissAnalyseGuard(),
$this->make(UnusedSkipResolver::class),
);
SimpleParameterProvider::setParameter(Option::SKIP, [
// skip-everywhere rule skip - forgotten at boot, not trackable, must be excluded
ThreeMan::class,
// rule-scoped path skip, never matched - intentional, must be reported even as mask
FifthElement::class => [self::UNUSED_RULE_MASK],
// rule-scoped path skip, matched - must not be reported
AnotherClassToSkip::class => [self::USED_RULE_MASK],
// global mask path skip - hard to spot, false-positive prone, must not be reported
self::GLOBAL_MASK,
]);
}
protected function tearDown(): void
{
SimpleParameterProvider::setParameter(Option::SKIP, []);
SimpleParameterProvider::setParameter(Option::REPORT_UNUSED_SKIPS, false);
SimpleParameterProvider::setParameter(Option::SKIPPED_NON_RECTOR_CLASSES, []);
}
public function testReportsSkippedNonRectorClass(): void
{
RectorConfigValidator::ensureRectorRulesExist([
// not a Rector rule, can never be skipped
AnotherClassToSkip::class => ['some/path'],
// Rector rule, must not be reported
OrdSingleByteRector::class => ['some/path'],
// post rector rule, must not be reported
NameImportingPostRector::class => ['some/path'],
]);
$this->missConfigurationReporter->reportSkippedNonRectorClasses();
$output = $this->bufferedOutput->fetch();
$this->assertStringContainsString('AnotherClassToSkip', $output);
$this->assertStringNotContainsString('OrdSingleByteRector', $output);
$this->assertStringNotContainsString('NameImportingPostRector', $output);
}
public function testReportsNothingOnRectorClassesOnly(): void
{
RectorConfigValidator::ensureRectorRulesExist([
OrdSingleByteRector::class => ['some/path'],
]);
$this->missConfigurationReporter->reportSkippedNonRectorClasses();
$this->assertSame('', $this->bufferedOutput->fetch());
}
public function testReportsOnlyTrackableUnusedSkips(): void
{
SimpleParameterProvider::setParameter(Option::REPORT_UNUSED_SKIPS, true);
// matched rule-scoped path is marked used scoped to its rule (class => [path])
$processResult = new ProcessResult([], [], 0, [
AnotherClassToSkip::class => [self::USED_RULE_MASK],
]);
$this->missConfigurationReporter->reportUnusedSkips($processResult);
$output = $this->bufferedOutput->fetch();
// unused rule-scoped path is reported as "rule => path", so both are shown
$this->assertStringContainsString('dead-rule', $output);
$this->assertStringContainsString('FifthElement', $output);
// matched rule-scoped path is excluded
$this->assertStringNotContainsString('matched-rule', $output);
$this->assertStringNotContainsString('AnotherClassToSkip', $output);
// global mask path is excluded (hard to spot, false-positive prone)
$this->assertStringNotContainsString('global-mask', $output);
// skip-everywhere rule skip is excluded (not trackable at runtime)
$this->assertStringNotContainsString('ThreeMan', $output);
}
public function testReportsNothingWhenDisabled(): void
{
SimpleParameterProvider::setParameter(Option::REPORT_UNUSED_SKIPS, false);
$processResult = new ProcessResult([], [], 0, []);
$this->missConfigurationReporter->reportUnusedSkips($processResult);
$this->assertSame('', $this->bufferedOutput->fetch());
}
}