Repository navigation
Expand file tree
/
Copy pathAutoloadFileParameterResolverTest.php
More file actions
72 lines (58 loc) · 2.53 KB
/
Copy pathAutoloadFileParameterResolverTest.php
File metadata and controls
72 lines (58 loc) · 2.53 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
<?php
declare(strict_types=1);
namespace Rector\Tests\Bootstrap;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
use Rector\Bootstrap\AutoloadFileParameterResolver;
use Rector\Caching\Config\FileHashComputer;
use Rector\Configuration\Option;
use Rector\Configuration\Parameter\SimpleParameterProvider;
use Rector\FileSystem\FilePathHelper;
use Symfony\Component\Filesystem\Filesystem;
final class AutoloadFileParameterResolverTest extends TestCase
{
protected function setUp(): void
{
SimpleParameterProvider::setParameter(Option::AUTOLOAD_FILE, '');
}
/**
* all spellings must resolve to the same value, or the main process and
* parallel workers, which receive the space-separated form, would compute
* different configuration hashes
*
* @param array<int, string> $argv
*/
#[DataProvider('provideArgvSpellings')]
public function testEverySpellingResolvesToSameRealPath(array $argv): void
{
AutoloadFileParameterResolver::resolveFromArgv($argv);
$this->assertSame(
(string) realpath(__FILE__),
SimpleParameterProvider::provideStringParameter(Option::AUTOLOAD_FILE)
);
}
/**
* @return iterable<string, array{array<int, string>}>
*/
public static function provideArgvSpellings(): iterable
{
$relativePath = 'tests/Bootstrap/' . basename(__FILE__);
yield 'long with space' => [['bin/rector', 'process', '--autoload-file', __FILE__]];
yield 'long with equals' => [['bin/rector', 'process', '--autoload-file=' . __FILE__]];
yield 'short with space' => [['bin/rector', 'process', '-a', __FILE__]];
yield 'relative path is normalized' => [['bin/rector', 'process', '-a', $relativePath]];
}
public function testWithoutOptionParameterStaysUntouched(): void
{
AutoloadFileParameterResolver::resolveFromArgv(['bin/rector', 'process', '--dry-run']);
$this->assertSame('', SimpleParameterProvider::provideStringParameter(Option::AUTOLOAD_FILE));
}
public function testResolvedAutoloadFileChangesConfigurationHash(): void
{
$fileHashComputer = new FileHashComputer(new FilePathHelper(new Filesystem()));
$configFilePath = __DIR__ . '/config/some_config.php';
$hashWithout = $fileHashComputer->compute($configFilePath);
AutoloadFileParameterResolver::resolveFromArgv(['bin/rector', 'process', '-a', __FILE__]);
$this->assertNotSame($hashWithout, $fileHashComputer->compute($configFilePath));
}
}