-
-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix class not found from Easy-Testing package (#2864)
* Fix class not found from Easy-Testing package * port Fixture updater * port Fixture updater * [ci-review] Rector Rectify * add missing methods on FixtureFileFinder * phpstan Co-authored-by: GitHub Action <action@github.com>
- Loading branch information
1 parent
6db4c0e
commit 8ce5353
Showing
13 changed files
with
155 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Testing\Fixture; | ||
|
||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
use Symplify\SmartFileSystem\SmartFileSystem; | ||
|
||
/** | ||
* @api | ||
*/ | ||
final class FixtureFileUpdater | ||
{ | ||
public static function updateFixtureContent( | ||
SmartFileInfo|string $originalFileInfo, | ||
string $changedContent, | ||
SmartFileInfo $fixtureFileInfo | ||
): void { | ||
if (! getenv('UPDATE_TESTS') && ! getenv('UT')) { | ||
return; | ||
} | ||
|
||
$newOriginalContent = self::resolveNewFixtureContent($originalFileInfo, $changedContent); | ||
|
||
self::getSmartFileSystem() | ||
->dumpFile($fixtureFileInfo->getRealPath(), $newOriginalContent); | ||
} | ||
|
||
public static function updateExpectedFixtureContent( | ||
string $newOriginalContent, | ||
SmartFileInfo $expectedFixtureFileInfo | ||
): void { | ||
if (! getenv('UPDATE_TESTS') && ! getenv('UT')) { | ||
return; | ||
} | ||
|
||
self::getSmartFileSystem() | ||
->dumpFile($expectedFixtureFileInfo->getRealPath(), $newOriginalContent); | ||
} | ||
|
||
private static function getSmartFileSystem(): SmartFileSystem | ||
{ | ||
return new SmartFileSystem(); | ||
} | ||
|
||
private static function resolveNewFixtureContent( | ||
SmartFileInfo|string $originalFileInfo, | ||
string $changedContent | ||
): string { | ||
if ($originalFileInfo instanceof SmartFileInfo) { | ||
$originalContent = $originalFileInfo->getContents(); | ||
} else { | ||
$originalContent = $originalFileInfo; | ||
} | ||
|
||
if ($originalContent === $changedContent) { | ||
return $originalContent; | ||
} | ||
|
||
return $originalContent . '-----' . PHP_EOL . $changedContent; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters