Repository navigation
Expand file tree
/
Copy pathApplicationFileProcessorTest.php
More file actions
100 lines (76 loc) · 3.68 KB
/
Copy pathApplicationFileProcessorTest.php
File metadata and controls
100 lines (76 loc) · 3.68 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
<?php
declare(strict_types=1);
namespace Rector\Tests\Application\ApplicationFileProcessor;
use Rector\Application\ApplicationFileProcessor;
use Rector\Caching\Detector\ChangedFilesDetector;
use Rector\DeadCode\Rector\ClassMethod\RemoveEmptyClassMethodRector;
use Rector\Testing\PHPUnit\AbstractLazyTestCase;
use Rector\ValueObject\Configuration;
final class ApplicationFileProcessorTest extends AbstractLazyTestCase
{
private ApplicationFileProcessor $applicationFileProcessor;
private ChangedFilesDetector $changedFilesDetector;
protected function setUp(): void
{
parent::setUp();
// reset the container to boot an isolated cache dir, so parallel test processes cannot
// wipe the shared default cache mid-run and flip the caching assertions below
self::$rectorConfig = null;
$this->bootFromConfigFiles([__DIR__ . '/config.php']);
$this->applicationFileProcessor = $this->make(ApplicationFileProcessor::class);
$this->changedFilesDetector = $this->make(ChangedFilesDetector::class);
}
protected function tearDown(): void
{
$this->changedFilesDetector->clear();
}
public function testCleanFileIsCachedAsUnchanged(): void
{
$filePath = __DIR__ . '/Source/CleanFile.php';
$this->applicationFileProcessor->processFiles([$filePath], new Configuration(isDryRun: true));
$this->assertFalse($this->changedFilesDetector->hasFileChanged($filePath));
}
public function testOnlyRuleRunCachesUnderOwnScopeWithoutPoisoningFullRun(): void
{
$filePath = __DIR__ . '/Source/CleanFile.php';
$this->applicationFileProcessor->processFiles([$filePath], new Configuration(
isDryRun: true,
onlyRule: RemoveEmptyClassMethodRector::class
));
// a repeated --only run hits its own scoped cache entry
$this->changedFilesDetector->setActiveScope(RemoveEmptyClassMethodRector::class, null);
$this->assertFalse($this->changedFilesDetector->hasFileChanged($filePath));
// a full run uses a different scope key, so it is not poisoned
$this->changedFilesDetector->setActiveScope(null, null);
$this->assertTrue($this->changedFilesDetector->hasFileChanged($filePath));
}
public function testOnlySuffixRunCachesUnderOwnScopeWithoutPoisoningFullRun(): void
{
$filePath = __DIR__ . '/Source/CleanFile.php';
$this->applicationFileProcessor->processFiles([$filePath], new Configuration(
isDryRun: true,
onlySuffix: 'Controller.php'
));
$this->changedFilesDetector->setActiveScope(null, 'Controller.php');
$this->assertFalse($this->changedFilesDetector->hasFileChanged($filePath));
$this->changedFilesDetector->setActiveScope(null, null);
$this->assertTrue($this->changedFilesDetector->hasFileChanged($filePath));
}
public function testMaxChangesStopsAfterLimit(): void
{
self::$rectorConfig = null;
$this->bootFromConfigFiles([__DIR__ . '/config-max-changes.php']);
$applicationFileProcessor = $this->make(ApplicationFileProcessor::class);
$filePaths = [
__DIR__ . '/Source/WithTwoClosuresFirst.php',
__DIR__ . '/Source/WithTwoClosuresSecond.php',
];
// each file holds 2 closures = 2 changes; the first file alone reaches the limit of 2,
// so the run stops before touching the second file - proving changes are counted, not files
$processResult = $applicationFileProcessor->processFiles($filePaths, new Configuration(
isDryRun: true,
maxChanges: 2,
));
$this->assertCount(1, $processResult->getFileDiffs());
}
}