rector/packages/Testing/Fixture/FixtureFileUpdater.php
Tomas Votruba aae549741f Updated Rector to commit 0cb3fd0feb464b4568e07607a05c794637aa2862
0cb3fd0feb [Php73] Handle crash Type Error on JsonThrowOnErrorRector (#4626)
2023-08-01 10:55:14 +00:00

29 lines
931 B
PHP

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