-
-
Notifications
You must be signed in to change notification settings - Fork 340
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Testing] Use own FixtureFileFinder to keep dependency low (#2858)
- Loading branch information
1 parent
b01ea04
commit 86ccf3f
Showing
23 changed files
with
243 additions
and
109 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Testing\Fixture; | ||
|
||
use Iterator; | ||
use Symfony\Component\Finder\Finder; | ||
use Symfony\Component\Finder\SplFileInfo; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
final class FixtureFileFinder | ||
{ | ||
/** | ||
* @return Iterator<array<int, SmartFileInfo>> | ||
*/ | ||
public static function yieldDirectory(string $directory, string $suffix = '*.php.inc'): Iterator | ||
{ | ||
$fileInfos = self::findFilesInDirectory($directory, $suffix); | ||
|
||
foreach ($fileInfos as $fileInfo) { | ||
// @todo is this one needed? maybe symfony is good enough :) | ||
$smartFileInfo = new SmartFileInfo($fileInfo->getRealPath()); | ||
yield [$smartFileInfo]; | ||
} | ||
} | ||
|
||
/** | ||
* @return SplFileInfo[] | ||
*/ | ||
private static function findFilesInDirectory(string $directory, string $suffix): array | ||
{ | ||
$finder = (new Finder()) | ||
->in($directory) | ||
->files() | ||
->name($suffix); | ||
|
||
$fileInfos = iterator_to_array($finder); | ||
return array_values($fileInfos); | ||
} | ||
} |
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,28 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace Rector\Testing\Fixture; | ||
|
||
use Nette\Utils\FileSystem; | ||
use Nette\Utils\Strings; | ||
use Webmozart\Assert\Assert; | ||
|
||
final class FixtureSplitter | ||
{ | ||
/** | ||
* @var string | ||
* @see https://regex101.com/r/zZDoyy/1 | ||
*/ | ||
public const SPLIT_LINE_REGEX = '#\-\-\-\-\-\r?\n#'; | ||
|
||
/** | ||
* @return array<string, string> | ||
*/ | ||
public static function loadFileAndSplitInputAndExpected(string $filePath): array | ||
{ | ||
Assert::fileExists($filePath); | ||
$fixtureFileContents = FileSystem::read($filePath); | ||
|
||
return Strings::split($fixtureFileContents, self::SPLIT_LINE_REGEX); | ||
} | ||
} |
Oops, something went wrong.