-
-
Notifications
You must be signed in to change notification settings - Fork 448
Expand file tree
/
Copy pathFileHashComputerTest.php
More file actions
69 lines (51 loc) · 2.38 KB
/
Copy pathFileHashComputerTest.php
File metadata and controls
69 lines (51 loc) · 2.38 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
<?php
declare(strict_types=1);
namespace Rector\Tests\Caching\Config\FileHashComputer;
use Rector\Caching\Config\FileHashComputer;
use Rector\Configuration\Option;
use Rector\Configuration\Parameter\SimpleParameterProvider;
use Rector\Testing\PHPUnit\AbstractLazyTestCase;
final class FileHashComputerTest extends AbstractLazyTestCase
{
private FileHashComputer $fileHashComputer;
/**
* @var mixed[]
*/
private array $originalRules = [];
/**
* @var mixed[]
*/
private array $originalFileExtensions = [];
protected function setUp(): void
{
parent::setUp();
$this->fileHashComputer = $this->make(FileHashComputer::class);
// the parameter bag is a global static shared across the whole test process, restore it after
$this->originalRules = SimpleParameterProvider::provideArrayParameter(Option::REGISTERED_RECTOR_RULES);
$this->originalFileExtensions = SimpleParameterProvider::provideArrayParameter(Option::FILE_EXTENSIONS);
}
protected function tearDown(): void
{
SimpleParameterProvider::setParameter(Option::REGISTERED_RECTOR_RULES, $this->originalRules);
SimpleParameterProvider::setParameter(Option::FILE_EXTENSIONS, $this->originalFileExtensions);
}
public function testOutputAffectingParameterChangesHash(): void
{
$configFilePath = __DIR__ . '/Fixture/rector.php';
SimpleParameterProvider::setParameter(Option::FILE_EXTENSIONS, ['php']);
$hashBefore = $this->fileHashComputer->compute($configFilePath);
SimpleParameterProvider::setParameter(Option::FILE_EXTENSIONS, ['php', 'phtml']);
$hashAfter = $this->fileHashComputer->compute($configFilePath);
$this->assertNotSame($hashBefore, $hashAfter);
}
public function testRuleChangeIsExcludedFromHash(): void
{
$configFilePath = __DIR__ . '/Fixture/rector.php';
SimpleParameterProvider::setParameter(Option::REGISTERED_RECTOR_RULES, ['Rector\\SomeRule']);
$hashBefore = $this->fileHashComputer->compute($configFilePath);
// registered rules are compared directionally, not by the strict hash
SimpleParameterProvider::setParameter(Option::REGISTERED_RECTOR_RULES, ['Rector\\SomeRule', 'Rector\\OtherRule']);
$hashAfter = $this->fileHashComputer->compute($configFilePath);
$this->assertSame($hashBefore, $hashAfter);
}
}