Repository navigation
Expand file tree
/
Copy pathMissConfigurationReporterTest.php
More file actions
98 lines (75 loc) · 3.79 KB
/
Copy pathMissConfigurationReporterTest.php
File metadata and controls
98 lines (75 loc) · 3.79 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
<?php
declare(strict_types=1);
namespace Rector\Tests\Reporting;
use Rector\Configuration\Option;
use Rector\Configuration\Parameter\SimpleParameterProvider;
use Rector\Configuration\VendorMissAnalyseGuard;
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\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);
}
public function testReportsOnlyTrackableUnusedSkips(): void
{
SimpleParameterProvider::setParameter(Option::REPORT_UNUSED_SKIPS, true);
// matched rule-scoped path is marked used scoped to its rule as "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());
}
}