|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace Rector\Tests\Bootstrap; |
| 6 | + |
| 7 | +use PHPUnit\Framework\Attributes\DataProvider; |
| 8 | +use PHPUnit\Framework\TestCase; |
| 9 | +use Rector\Bootstrap\CliOptionValueResolver; |
| 10 | + |
| 11 | +final class CliOptionValueResolverTest extends TestCase |
| 12 | +{ |
| 13 | + /** |
| 14 | + * @param array<int, mixed> $argv |
| 15 | + */ |
| 16 | + #[DataProvider('provideData')] |
| 17 | + public function test(array $argv, ?string $expectedValue): void |
| 18 | + { |
| 19 | + $this->assertSame($expectedValue, CliOptionValueResolver::resolve($argv, ['--config', '-c'])); |
| 20 | + } |
| 21 | + |
| 22 | + /** |
| 23 | + * @return iterable<string, array{array<int, mixed>, string|null}> |
| 24 | + */ |
| 25 | + public static function provideData(): iterable |
| 26 | + { |
| 27 | + yield 'long with space' => [['bin/rector', 'process', '--config', 'rector.php'], 'rector.php']; |
| 28 | + yield 'long with equals' => [['bin/rector', 'process', '--config=rector.php'], 'rector.php']; |
| 29 | + yield 'short with space' => [['bin/rector', 'process', '-c', 'rector.php'], 'rector.php']; |
| 30 | + yield 'short with equals' => [['bin/rector', 'process', '-c=rector.php'], 'rector.php']; |
| 31 | + yield 'first occurrence wins' => [['bin/rector', '-c', 'first.php', '--config', 'second.php'], 'first.php']; |
| 32 | + yield 'missing value' => [['bin/rector', 'process', '--config'], null]; |
| 33 | + yield 'missing option' => [['bin/rector', 'process', '--dry-run'], null]; |
| 34 | + yield 'similar prefix is not matched' => [['bin/rector', 'process', '--configuration', 'rector.php'], null]; |
| 35 | + yield 'after end of options' => [['bin/rector', 'process', '--', '--config', 'rector.php'], null]; |
| 36 | + } |
| 37 | +} |
0 commit comments