Skip to content
Merged
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\Caching\Config\FileHashComputer;

use PHPUnit\Framework\Attributes\RunInSeparateProcess;
use Rector\Caching\Config\FileHashComputer;
use Rector\Core\Configuration\Option;
use Rector\Core\Configuration\Parameter\SimpleParameterProvider;
use Rector\Testing\PHPUnit\AbstractLazyTestCase;

final class FileHashComputerTest extends AbstractLazyTestCase
{
private FileHashComputer $fileHashComputer;

protected function setUp(): void
{
$this->fileHashComputer = $this->make(FileHashComputer::class);
}

#[RunInSeparateProcess]
public function testRectorPhpChanged(): void
{
$this->bootFromConfigFiles([__DIR__ . '/Fixture/rector.php']);

$hashedFile = $this->fileHashComputer->compute(__DIR__ . '/Fixture/rector.php');

copy(__DIR__ . '/Fixture/rector.php', __DIR__ . '/Fixture/rector_temp.php');
copy(__DIR__ . '/Fixture/updated_rector_rule.php', __DIR__ . '/Fixture/rector.php');

SimpleParameterProvider::setParameter(Option::REGISTERED_RECTOR_RULES, null);

$this->bootFromConfigFiles([__DIR__ . '/Fixture/rector.php']);

$newHashedFile = $this->fileHashComputer->compute(__DIR__ . '/Fixture/rector.php');
rename(__DIR__ . '/Fixture/rector_temp.php', __DIR__ . '/Fixture/rector.php');

$this->assertNotSame($newHashedFile, $hashedFile);
}

#[RunInSeparateProcess]
public function testRectorPhpNotChanged(): void
{
$this->bootFromConfigFiles([__DIR__ . '/Fixture/rector.php']);

$hashedFile = $this->fileHashComputer->compute(__DIR__ . '/Fixture/rector.php');

copy(__DIR__ . '/Fixture/rector.php', __DIR__ . '/Fixture/rector_temp_equal.php');
copy(__DIR__ . '/Fixture/rector_rule_equals.php', __DIR__ . '/Fixture/rector.php');

SimpleParameterProvider::setParameter(Option::REGISTERED_RECTOR_RULES, null);

$this->bootFromConfigFiles([__DIR__ . '/Fixture/rector.php']);

$newHashedFile = $this->fileHashComputer->compute(__DIR__ . '/Fixture/rector.php');
rename(__DIR__ . '/Fixture/rector_temp_equal.php', __DIR__ . '/Fixture/rector.php');

$this->assertSame($newHashedFile, $hashedFile);
}
}
10 changes: 10 additions & 0 deletions packages-tests/Caching/Config/FileHashComputer/Fixture/rector.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rules([DeclareStrictTypesRector::class]);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rules([

// only spaced/comment added, no need to clear cache
DeclareStrictTypesRector::class

]);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\Expression\RemoveDeadStmtRector;
use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rules([
DeclareStrictTypesRector::class,
RemoveDeadStmtRector::class,
]);
};