Repository navigation
Expand file tree
/
Copy pathApplicationFileProcessorTest.php
More file actions
92 lines (72 loc) · 3.43 KB
/
Copy pathApplicationFileProcessorTest.php
File metadata and controls
92 lines (72 loc) · 3.43 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
<?php
declare(strict_types=1);
namespace Rector\Tests\Application\ApplicationFileProcessor;
use Illuminate\Container\Container;
use Rector\Application\ApplicationFileProcessor;
use Rector\Caching\Cache;
use Rector\Caching\CacheFactory;
use Rector\Caching\Detector\ChangedFilesDetector;
use Rector\Configuration\Option;
use Rector\Configuration\Parameter\SimpleParameterProvider;
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();
// isolate the cache directory to this test - the default directory is shared across all
// parallel test chunks, and FileCacheStorage::clear() deletes the whole directory, so a
// sibling chunk can wipe this test's cache between save and load and flip the assertions
$rectorConfig = self::getContainer();
SimpleParameterProvider::setParameter(
Option::CACHE_DIR,
sys_get_temp_dir() . '/rector_test_application_file_processor'
);
$rectorConfig->singleton(
Cache::class,
static fn (Container $container): Cache => $container->make(CacheFactory::class)->create()
);
$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));
}
}