|
5 | 5 | namespace Rector\Tests\Configuration; |
6 | 6 |
|
7 | 7 | use Rector\Configuration\ConfigurationFactory; |
| 8 | +use Rector\Configuration\Option; |
| 9 | +use Rector\Configuration\Parameter\SimpleParameterProvider; |
| 10 | +use Rector\Console\ProcessConfigureDecorator; |
8 | 11 | use Rector\FileSystem\FilesFinder; |
9 | 12 | use Rector\Testing\PHPUnit\AbstractLazyTestCase; |
| 13 | +use Symfony\Component\Console\Command\Command; |
| 14 | +use Symfony\Component\Console\Input\ArrayInput; |
10 | 15 |
|
11 | 16 | final class ConfigurationFactoryTest extends AbstractLazyTestCase |
12 | 17 | { |
@@ -42,4 +47,55 @@ public function test(): void |
42 | 47 | realpath($thirdFilePath), |
43 | 48 | ); |
44 | 49 | } |
| 50 | + |
| 51 | + public function testPublishesCommandLinePathsAsSourceParameter(): void |
| 52 | + { |
| 53 | + SimpleParameterProvider::setParameter(Option::PATHS, [__DIR__ . '/config']); |
| 54 | + |
| 55 | + $this->make(ConfigurationFactory::class) |
| 56 | + ->createFromInput($this->createInput([__DIR__ . '/Source'])); |
| 57 | + |
| 58 | + $this->assertSame( |
| 59 | + [__DIR__ . '/Source'], |
| 60 | + SimpleParameterProvider::provideArrayParameter(Option::SOURCE) |
| 61 | + ); |
| 62 | + } |
| 63 | + |
| 64 | + public function testPublishesConfiguredPathsAsSourceParameterWhenNoneGivenOnTheCommandLine(): void |
| 65 | + { |
| 66 | + SimpleParameterProvider::setParameter(Option::PATHS, [__DIR__ . '/config']); |
| 67 | + |
| 68 | + $this->make(ConfigurationFactory::class) |
| 69 | + ->createFromInput($this->createInput([])); |
| 70 | + |
| 71 | + $this->assertSame( |
| 72 | + [__DIR__ . '/config'], |
| 73 | + SimpleParameterProvider::provideArrayParameter(Option::SOURCE) |
| 74 | + ); |
| 75 | + } |
| 76 | + |
| 77 | + public function testSourceParameterIsOutsideTheCacheInvalidationHash(): void |
| 78 | + { |
| 79 | + // The processed paths change per invocation. Were they hashed, running Rector on a |
| 80 | + // single file and then on the whole project would drop the cache each time. |
| 81 | + SimpleParameterProvider::setParameter(Option::SOURCE, ['src']); |
| 82 | + $hashForOnePath = SimpleParameterProvider::hashForCacheInvalidation(); |
| 83 | + |
| 84 | + SimpleParameterProvider::setParameter(Option::SOURCE, ['tests', 'src/Some/Other.php']); |
| 85 | + |
| 86 | + $this->assertSame($hashForOnePath, SimpleParameterProvider::hashForCacheInvalidation()); |
| 87 | + } |
| 88 | + |
| 89 | + /** |
| 90 | + * @param string[] $paths |
| 91 | + */ |
| 92 | + private function createInput(array $paths): ArrayInput |
| 93 | + { |
| 94 | + $command = new Command('process'); |
| 95 | + ProcessConfigureDecorator::decorate($command); |
| 96 | + |
| 97 | + return new ArrayInput([ |
| 98 | + Option::SOURCE => $paths, |
| 99 | + ], $command->getDefinition()); |
| 100 | + } |
45 | 101 | } |
0 commit comments