Repository navigation
Expand file tree
/
Copy pathValidateConfigCommandTest.php
More file actions
115 lines (95 loc) · 3.88 KB
/
Copy pathValidateConfigCommandTest.php
File metadata and controls
115 lines (95 loc) · 3.88 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
<?php
declare(strict_types=1);
namespace Rector\Tests\Console\Command;
use Nette\Utils\Json;
use Rector\Configuration\Option;
use Rector\Configuration\Parameter\SimpleParameterProvider;
use Rector\Configuration\VendorMissAnalyseGuard;
use Rector\Console\Command\ValidateConfigCommand;
use Rector\Console\ExitCode;
use Rector\Php85\Rector\FuncCall\OrdSingleByteRector;
use Rector\Reporting\DeprecatedRulesReporter;
use Rector\Reporting\MissConfigurationReporter;
use Rector\Reporting\UnusedSkipResolver;
use Rector\Skipper\Skipper\Skipper;
use Rector\Testing\PHPUnit\AbstractLazyTestCase;
use Rector\Tests\Console\Command\Source\DeprecatedFixtureRule;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Output\BufferedOutput;
use Symfony\Component\Console\Style\SymfonyStyle;
use Symfony\Component\Console\Tester\CommandTester;
final class ValidateConfigCommandTest extends AbstractLazyTestCase
{
private CommandTester $commandTester;
protected function setUp(): void
{
parent::setUp();
// clean baseline, so params leaked by other tests in the shared process do not count as issues
foreach ([
Option::SKIP,
Option::SKIPPED_NON_RECTOR_CLASSES,
Option::SKIPPED_RECTOR_RULES,
Option::SKIPPED_START_WITH_SHORT_OPEN_TAG_FILES,
Option::DEPRECATED_ATTRIBUTES_SETS_ARGS,
Option::DEPRECATED_COMPOSER_BASED_ARGS,
Option::ROOT_STANDALONE_REGISTERED_RULES,
Option::SET_REGISTERED_RULES,
] as $optionName) {
SimpleParameterProvider::setParameter($optionName, []);
}
$symfonyStyle = new SymfonyStyle(new ArrayInput([]), new BufferedOutput());
$validateConfigCommand = new ValidateConfigCommand(
$symfonyStyle,
new DeprecatedRulesReporter($symfonyStyle),
new MissConfigurationReporter(
$symfonyStyle,
new VendorMissAnalyseGuard(),
$this->make(UnusedSkipResolver::class),
),
$this->make(Skipper::class),
);
$this->commandTester = new CommandTester($validateConfigCommand);
}
protected function tearDown(): void
{
SimpleParameterProvider::setParameter(Option::REGISTERED_RECTOR_RULES, []);
}
public function testFailsOnDeprecatedRegisteredRule(): void
{
SimpleParameterProvider::setParameter(Option::REGISTERED_RECTOR_RULES, [DeprecatedFixtureRule::class]);
$this->assertSame(ExitCode::FAILURE, $this->commandTester->execute([]));
}
public function testSucceedsOnCleanConfig(): void
{
SimpleParameterProvider::setParameter(Option::REGISTERED_RECTOR_RULES, [OrdSingleByteRector::class]);
$this->assertSame(ExitCode::SUCCESS, $this->commandTester->execute([]));
}
public function testJsonOutputOnCleanConfig(): void
{
SimpleParameterProvider::setParameter(Option::REGISTERED_RECTOR_RULES, [OrdSingleByteRector::class]);
ob_start();
$exitCode = $this->commandTester->execute([
'--output-format' => 'json',
]);
$json = (string) ob_get_clean();
$this->assertSame(ExitCode::SUCCESS, $exitCode);
$this->assertSame([
'valid' => true,
'issue_count' => 0,
], Json::decode($json, forceArrays: true));
}
public function testJsonOutputOnDeprecatedRegisteredRule(): void
{
SimpleParameterProvider::setParameter(Option::REGISTERED_RECTOR_RULES, [DeprecatedFixtureRule::class]);
ob_start();
$exitCode = $this->commandTester->execute([
'--output-format' => 'json',
]);
$json = (string) ob_get_clean();
$this->assertSame(ExitCode::FAILURE, $exitCode);
$this->assertSame([
'valid' => false,
'issue_count' => 1,
], Json::decode($json, forceArrays: true));
}
}