Repository navigation
Expand file tree
/
Copy pathConfigurationFactoryTest.php
More file actions
108 lines (86 loc) · 3.69 KB
/
Copy pathConfigurationFactoryTest.php
File metadata and controls
108 lines (86 loc) · 3.69 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
<?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 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, []);
}
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());
}
/**
* @param string[] $paths
*/
private function createInput(array $paths): ArrayInput
{
$command = new Command('process');
ProcessConfigureDecorator::decorate($command);
return new ArrayInput([
Option::SOURCE => $paths,
], $command->getDefinition());
}
}