Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/Application/ApplicationFileProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,11 @@ private function processFile(File $file, Configuration $configuration): FileProc
if ($fileProcessResult->getSystemErrors() !== []) {
$this->changedFilesDetector->invalidateFile($file->getFilePath());
} elseif (! $configuration->isDryRun() || ! $fileProcessResult->getFileDiff() instanceof FileDiff) {
$this->changedFilesDetector->cacheFile($file->getFilePath());
// a file clean under a subset of rules is not necessarily clean under all rules,
// caching it would hide its pending changes from the next full run
if ($configuration->getOnlyRule() === null && $configuration->getOnlySuffix() === null) {
$this->changedFilesDetector->cacheFile($file->getFilePath());
}
}

return $fileProcessResult;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?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();

$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/clean_file.php';

$this->applicationFileProcessor->processFiles([$filePath], new Configuration(isDryRun: true));

$this->assertFalse($this->changedFilesDetector->hasFileChanged($filePath));
}

public function testOnlyRuleRunDoesNotCacheFileAsUnchanged(): void
{
$filePath = __DIR__ . '/Source/clean_file.php';

$this->applicationFileProcessor->processFiles([$filePath], new Configuration(
isDryRun: true,
onlyRule: RemoveEmptyClassMethodRector::class
));

// a file clean under one rule is not necessarily clean under all rules
$this->assertTrue($this->changedFilesDetector->hasFileChanged($filePath));
}

public function testOnlySuffixRunDoesNotCacheFileAsUnchanged(): void
{
$filePath = __DIR__ . '/Source/clean_file.php';

$this->applicationFileProcessor->processFiles([$filePath], new Configuration(
isDryRun: true,
onlySuffix: 'Controller.php'
));

$this->assertTrue($this->changedFilesDetector->hasFileChanged($filePath));
}
}
11 changes: 11 additions & 0 deletions tests/Application/ApplicationFileProcessor/Source/clean_file.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

final class CleanFile
{
public function run(): string
{
return 'nothing to change';
}
}
Loading