Skip to content
Open
Show file tree
Hide file tree
Changes from all 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/CleanFile.php';

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

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

public function testOnlyRuleRunDoesNotCacheFileAsUnchanged(): void
{
$filePath = __DIR__ . '/Source/CleanFile.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/CleanFile.php';

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

$this->assertTrue($this->changedFilesDetector->hasFileChanged($filePath));
}
}
13 changes: 13 additions & 0 deletions tests/Application/ApplicationFileProcessor/Source/CleanFile.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
Comment thread
samsonasik marked this conversation as resolved.

declare(strict_types=1);

namespace Rector\Tests\Application\ApplicationFileProcessor\Source;

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