rector/packages/Testing/Fixture/FixtureFileUpdater.php
Tomas Votruba 671f50c702 Updated Rector to commit ee715396945596fffb158ff8278749feb01ea01a
ee71539694 [NodeTypeResolver] Use isScalar()->yes() usage on StaticTypeAnalyzer and ScalarTypeComparator services (#5099)
2023-10-01 01:36:35 +00:00

28 lines
864 B
PHP

<?php
declare (strict_types=1);
namespace Rector\Testing\Fixture;
use RectorPrefix202310\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;
}
}