mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-03 09:50:49 +00:00
aae549741f
0cb3fd0feb
[Php73] Handle crash Type Error on JsonThrowOnErrorRector (#4626)
29 lines
931 B
PHP
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;
|
|
}
|
|
}
|