rector/packages/Testing/Fixture/FixtureFileUpdater.php
Tomas Votruba 7ba32aac1f Updated Rector to commit e12c73eb339a847bcd717025abf5bc43f1cd0e4c
e12c73eb33 [psr-4] Move tests to main namespace, as part of /src and /packages merge - step 2 (#5407)
2024-01-01 00:20:45 +00:00

28 lines
864 B
PHP

<?php
declare (strict_types=1);
namespace Rector\Testing\Fixture;
use RectorPrefix202401\Nette\Utils\FileSystem;
final class FixtureFileUpdater
{
/**
* @api
*/
public static function updateFixtureContent(string $originalContent, string $changedContent, string $fixtureFilePath) : void
{
if (!\getenv('UPDATE_TESTS') && !\getenv('UT')) {
return;
}
$newOriginalContent = self::resolveNewFixtureContent($originalContent, $changedContent);
FileSystem::write($fixtureFilePath, $newOriginalContent);
}
private static function resolveNewFixtureContent(string $originalContent, string $changedContent) : string
{
if ($originalContent === $changedContent) {
return $originalContent;
}
return $originalContent . '-----' . \PHP_EOL . $changedContent;
}
}