Repository navigation
Expand file tree
/
Copy pathConfigurationFactoryTest.php
More file actions
137 lines (109 loc) · 4.87 KB
/
Copy pathConfigurationFactoryTest.php
File metadata and controls
137 lines (109 loc) · 4.87 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
136
137
<?php
declare(strict_types=1);
namespace Rector\Tests\Configuration;
use Rector\Configuration\ConfigurationFactory;
use Rector\Configuration\Option;
use Rector\Configuration\Parameter\SimpleParameterProvider;
use Rector\Console\ProcessConfigureDecorator;
use Rector\FileSystem\FilesFinder;
use Rector\Testing\PHPUnit\AbstractLazyTestCase;
use stdClass;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
final class ConfigurationFactoryTest extends AbstractLazyTestCase
{
protected function tearDown(): void
{
SimpleParameterProvider::setParameter(Option::IS_RUN_NARROWED, false);
SimpleParameterProvider::setParameter(Option::SOURCE, []);
SimpleParameterProvider::setParameter(Option::PATHS, []);
SimpleParameterProvider::setParameter(Option::RULE_CONFIGURATIONS, []);
}
public function test(): void
{
$configurationFactory = $this->make(ConfigurationFactory::class);
$configuration = $configurationFactory->createForTests([
__DIR__ . '/../../tests-paths/path/*/some_directory/*',
__DIR__ . '/../../tests-paths/path/NoExtensionFile',
]);
$filesFinder = $this->make(FilesFinder::class);
$filePaths = $filesFinder->findInDirectoriesAndFiles($configuration->getPaths());
$this->assertCount(3, $filePaths);
$firstFilePath = $filePaths[0];
$secondFilePath = $filePaths[1];
$thirdFilePath = $filePaths[2];
$this->assertSame(
realpath(__DIR__ . '/../../tests-paths/path/wildcard-nested/some_directory/AnotherFile.php'),
realpath($firstFilePath)
);
$this->assertSame(
realpath(__DIR__ . '/../../tests-paths/path/wildcard-next/some_directory/YetAnotherFile.php'),
realpath($secondFilePath),
);
$this->assertSame(
realpath(__DIR__ . '/../../tests-paths/path/NoExtensionFile'),
realpath($thirdFilePath),
);
}
public function testPublishesCommandLinePathsAsSourceParameter(): void
{
SimpleParameterProvider::setParameter(Option::PATHS, [__DIR__ . '/config']);
$this->make(ConfigurationFactory::class)
->createFromInput($this->createInput([__DIR__ . '/Source']));
$this->assertSame(
[__DIR__ . '/Source'],
SimpleParameterProvider::provideArrayParameter(Option::SOURCE)
);
}
public function testPublishesConfiguredPathsAsSourceParameterWhenNoneGivenOnTheCommandLine(): void
{
SimpleParameterProvider::setParameter(Option::PATHS, [__DIR__ . '/config']);
$this->make(ConfigurationFactory::class)
->createFromInput($this->createInput([]));
$this->assertSame(
[__DIR__ . '/config'],
SimpleParameterProvider::provideArrayParameter(Option::SOURCE)
);
}
public function testSourceParameterIsOutsideTheCacheInvalidationHash(): void
{
// The processed paths change per invocation. Were they hashed, running Rector on a
// single file and then on the whole project would drop the cache each time.
SimpleParameterProvider::setParameter(Option::SOURCE, ['src']);
$hashForOnePath = SimpleParameterProvider::hashForCacheInvalidation();
SimpleParameterProvider::setParameter(Option::SOURCE, ['tests', 'src/Some/Other.php']);
$this->assertSame($hashForOnePath, SimpleParameterProvider::hashForCacheInvalidation());
}
public function testObjectPropertyOrderIsOutsideTheCacheInvalidationHash(): void
{
// PHPStan Turbo workers declare e.g. MixedType properties in another order than the main process,
// the same configured value must hash alike in both
$firstOrder = new stdClass();
$firstOrder->isExplicitMixed = false;
$firstOrder->subtractedType = null;
SimpleParameterProvider::setParameter(Option::RULE_CONFIGURATIONS, [
'SomeRector' => [$firstOrder],
]);
$firstOrderHash = SimpleParameterProvider::hashForCacheInvalidation();
$secondOrder = new stdClass();
$secondOrder->subtractedType = null;
$secondOrder->isExplicitMixed = false;
SimpleParameterProvider::setParameter(Option::RULE_CONFIGURATIONS, [
'SomeRector' => [$secondOrder],
]);
$this->assertSame($firstOrderHash, SimpleParameterProvider::hashForCacheInvalidation());
$secondOrder->isExplicitMixed = true;
$this->assertNotSame($firstOrderHash, SimpleParameterProvider::hashForCacheInvalidation());
}
/**
* @param string[] $paths
*/
private function createInput(array $paths): ArrayInput
{
$command = new Command('process');
ProcessConfigureDecorator::decorate($command);
return new ArrayInput([
Option::SOURCE => $paths,
], $command->getDefinition());
}
}