Skip to content

Commit d197e99

Browse files
committed
Updated Rector to commit 86ccf3f6854c78c6b7b06b8471d922724cb6542b
rectorphp/rector-src@86ccf3f [Testing] Use own FixtureFileFinder to keep dependency low (rectorphp#2858)
1 parent eb540c7 commit d197e99

11 files changed

+144
-33
lines changed

packages/FileSystemRector/Parser/FileInfoParser.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@
88
use Rector\Core\PhpParser\Parser\RectorParser;
99
use Rector\Core\ValueObject\Application\File;
1010
use Rector\NodeTypeResolver\NodeScopeAndMetadataDecorator;
11+
use Rector\Testing\Fixture\FixtureTempFileDumper;
1112
use Symplify\SmartFileSystem\SmartFileInfo;
13+
/**
14+
* Only for testing, @todo move to testing
15+
*/
1216
final class FileInfoParser
1317
{
1418
/**
@@ -34,9 +38,13 @@ public function __construct(NodeScopeAndMetadataDecorator $nodeScopeAndMetadataD
3438
}
3539
/**
3640
* @return Stmt[]
41+
* @param \Symplify\SmartFileSystem\SmartFileInfo|string $smartFileInfo
3742
*/
38-
public function parseFileInfoToNodesAndDecorate(SmartFileInfo $smartFileInfo) : array
43+
public function parseFileInfoToNodesAndDecorate($smartFileInfo) : array
3944
{
45+
if (\is_string($smartFileInfo)) {
46+
$smartFileInfo = FixtureTempFileDumper::dump($smartFileInfo);
47+
}
4048
$stmts = $this->rectorParser->parseFile($smartFileInfo);
4149
$stmts = $this->fileWithoutNamespaceNodeTraverser->traverse($stmts);
4250
$file = new File($smartFileInfo, $smartFileInfo->getContents());
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
declare (strict_types=1);
4+
namespace Rector\Testing\Fixture;
5+
6+
use Iterator;
7+
use RectorPrefix202208\Symfony\Component\Finder\Finder;
8+
use RectorPrefix202208\Symfony\Component\Finder\SplFileInfo;
9+
use Symplify\SmartFileSystem\SmartFileInfo;
10+
final class FixtureFileFinder
11+
{
12+
/**
13+
* @return Iterator<array<int, SmartFileInfo>>
14+
*/
15+
public static function yieldDirectory(string $directory, string $suffix = '*.php.inc') : Iterator
16+
{
17+
$fileInfos = self::findFilesInDirectory($directory, $suffix);
18+
foreach ($fileInfos as $fileInfo) {
19+
// @todo is this one needed? maybe symfony is good enough :)
20+
$smartFileInfo = new SmartFileInfo($fileInfo->getRealPath());
21+
(yield [$smartFileInfo]);
22+
}
23+
}
24+
/**
25+
* @return SplFileInfo[]
26+
*/
27+
private static function findFilesInDirectory(string $directory, string $suffix) : array
28+
{
29+
$finder = (new Finder())->in($directory)->files()->name($suffix);
30+
$fileInfos = \iterator_to_array($finder);
31+
return \array_values($fileInfos);
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
declare (strict_types=1);
4+
namespace Rector\Testing\Fixture;
5+
6+
use RectorPrefix202208\Nette\Utils\FileSystem;
7+
use RectorPrefix202208\Nette\Utils\Strings;
8+
use RectorPrefix202208\Webmozart\Assert\Assert;
9+
final class FixtureSplitter
10+
{
11+
/**
12+
* @var string
13+
* @see https://regex101.com/r/zZDoyy/1
14+
*/
15+
public const SPLIT_LINE_REGEX = '#\\-\\-\\-\\-\\-\\r?\\n#';
16+
/**
17+
* @return array<string, string>
18+
*/
19+
public static function loadFileAndSplitInputAndExpected(string $filePath) : array
20+
{
21+
Assert::fileExists($filePath);
22+
$fixtureFileContents = FileSystem::read($filePath);
23+
return Strings::split($fixtureFileContents, self::SPLIT_LINE_REGEX);
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
declare (strict_types=1);
4+
namespace Rector\Testing\Fixture;
5+
6+
use RectorPrefix202208\Nette\Utils\FileSystem;
7+
use Symplify\SmartFileSystem\SmartFileInfo;
8+
final class FixtureTempFileDumper
9+
{
10+
/**
11+
* @var string
12+
*/
13+
public const TEMP_FIXTURE_DIRECTORY = '/rector/tests_fixture_';
14+
public static function dump(string $fileContents, string $suffix = 'php') : SmartFileInfo
15+
{
16+
// the "php" suffix is important, because that will hook into \Rector\Core\Application\FileProcessor\PhpFileProcessor
17+
$temporaryFileName = \sys_get_temp_dir() . self::TEMP_FIXTURE_DIRECTORY . '/' . \md5($fileContents) . '.' . $suffix;
18+
FileSystem::write($temporaryFileName, $fileContents);
19+
return new SmartFileInfo($temporaryFileName);
20+
}
21+
}

packages/Testing/PHPUnit/AbstractRectorTestCase.php

+33-16
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
namespace Rector\Testing\PHPUnit;
55

66
use Iterator;
7+
use RectorPrefix202208\Nette\Utils\Strings;
78
use PHPStan\Analyser\NodeScopeResolver;
89
use PHPUnit\Framework\ExpectationFailedException;
910
use RectorPrefix202208\Psr\Container\ContainerInterface;
@@ -16,10 +17,12 @@
1617
use Rector\Core\ValueObject\Application\File;
1718
use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider;
1819
use Rector\Testing\Contract\RectorTestInterface;
20+
use Rector\Testing\Fixture\FixtureFileFinder;
21+
use Rector\Testing\Fixture\FixtureSplitter;
22+
use Rector\Testing\Fixture\FixtureTempFileDumper;
1923
use Rector\Testing\PHPUnit\Behavior\MovingFilesTrait;
20-
use RectorPrefix202208\Symplify\EasyTesting\DataProvider\StaticFixtureFinder;
24+
use SplFileInfo;
2125
use RectorPrefix202208\Symplify\EasyTesting\DataProvider\StaticFixtureUpdater;
22-
use RectorPrefix202208\Symplify\EasyTesting\StaticFixtureSplitter;
2326
use RectorPrefix202208\Symplify\PackageBuilder\Parameter\ParameterProvider;
2427
use Symplify\SmartFileSystem\SmartFileInfo;
2528
abstract class AbstractRectorTestCase extends \Rector\Testing\PHPUnit\AbstractTestCase implements RectorTestInterface
@@ -59,6 +62,7 @@ protected function setUp() : void
5962
$this->applicationFileProcessor = $this->getService(ApplicationFileProcessor::class);
6063
$this->parameterProvider = $this->getService(ParameterProvider::class);
6164
$this->dynamicSourceLocatorProvider = $this->getService(DynamicSourceLocatorProvider::class);
65+
// restore added and removed files to 0
6266
$this->removedAndAddedFilesCollector = $this->getService(RemovedAndAddedFilesCollector::class);
6367
$this->removedAndAddedFilesCollector->reset();
6468
/** @var AdditionalAutoloader $additionalAutoloader */
@@ -79,30 +83,43 @@ protected function tearDown() : void
7983
*/
8084
protected function yieldFilesFromDirectory(string $directory, string $suffix = '*.php.inc') : Iterator
8185
{
82-
return StaticFixtureFinder::yieldDirectoryExclusively($directory, $suffix);
83-
}
84-
/**
85-
* @return Iterator<string, array<int, SmartFileInfo>>
86-
*/
87-
protected function yieldFilesWithPathnameFromDirectory(string $directory, string $suffix = '*.php.inc') : Iterator
88-
{
89-
return StaticFixtureFinder::yieldDirectoryExclusivelyWithRelativePathname($directory, $suffix);
86+
return FixtureFileFinder::yieldDirectory($directory, $suffix);
9087
}
9188
protected function isWindows() : bool
9289
{
9390
return \strncasecmp(\PHP_OS, 'WIN', 3) === 0;
9491
}
95-
protected function doTestFileInfo(SmartFileInfo $fixtureFileInfo, bool $allowMatches = \true) : void
92+
protected function doTestFileInfo(SmartFileInfo $fixtureFileInfo)
9693
{
97-
$inputFileInfoAndExpectedFileInfo = StaticFixtureSplitter::splitFileInfoToLocalInputAndExpectedFileInfos($fixtureFileInfo);
98-
$inputFileInfo = $inputFileInfoAndExpectedFileInfo->getInputFileInfo();
94+
if (Strings::match($fixtureFileInfo->getContents(), FixtureSplitter::SPLIT_LINE_REGEX)) {
95+
// changed content
96+
[$inputFileContents, $expectedFileContents] = FixtureSplitter::loadFileAndSplitInputAndExpected($fixtureFileInfo->getRealPath());
97+
} else {
98+
// no change
99+
$inputFileContents = $fixtureFileInfo->getContents();
100+
$expectedFileContents = $fixtureFileInfo->getContents();
101+
}
102+
$fileSuffix = $this->resolveOriginalFixtureFileSuffix($fixtureFileInfo);
103+
$inputFileInfo = FixtureTempFileDumper::dump($inputFileContents, $fileSuffix);
104+
$expectedFileInfo = FixtureTempFileDumper::dump($expectedFileContents, $fileSuffix);
99105
$this->originalTempFileInfo = $inputFileInfo;
100-
$expectedFileInfo = $inputFileInfoAndExpectedFileInfo->getExpectedFileInfo();
101-
$this->doTestFileMatchesExpectedContent($inputFileInfo, $expectedFileInfo, $fixtureFileInfo, $allowMatches);
106+
$this->doTestFileMatchesExpectedContent($inputFileInfo, $expectedFileInfo, $fixtureFileInfo);
107+
//, $allowMatches);
102108
}
103109
protected function getFixtureTempDirectory() : string
104110
{
105-
return \sys_get_temp_dir() . '/_temp_fixture_easy_testing';
111+
return \sys_get_temp_dir() . FixtureTempFileDumper::TEMP_FIXTURE_DIRECTORY;
112+
}
113+
private function resolveOriginalFixtureFileSuffix(SplFileInfo $splFileInfo) : string
114+
{
115+
$fixtureRealPath = $splFileInfo->getRealPath();
116+
if (\substr_compare($fixtureRealPath, '.inc', -\strlen('.inc')) === 0) {
117+
$fixtureRealPath = \rtrim($fixtureRealPath, '.inc');
118+
}
119+
if (\substr_compare($fixtureRealPath, '.blade.php', -\strlen('.blade.php')) === 0) {
120+
return 'blade.php';
121+
}
122+
return \pathinfo($fixtureRealPath, \PATHINFO_EXTENSION);
106123
}
107124
private function includePreloadFilesAndScoperAutoload() : void
108125
{

packages/Testing/PHPUnit/Behavior/MovingFilesTrait.php

+3-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use Rector\Core\Application\FileSystem\RemovedAndAddedFilesCollector;
77
use Rector\Core\PhpParser\Printer\NodesWithFileDestinationPrinter;
88
use Rector\FileSystemRector\ValueObject\AddedFileWithContent;
9+
use Rector\Testing\Fixture\FixtureTempFileDumper;
910
use RectorPrefix202208\Webmozart\Assert\Assert;
1011
/**
1112
* @property-read RemovedAndAddedFilesCollector $removedAndAddedFilesCollector
@@ -34,8 +35,8 @@ protected function assertFilesWereAdded(array $expectedAddedFileWithContents) :
3435
* to make work in all OSs, for example:
3536
* In MacOS, the realpath() of sys_get_temp_dir() pointed to /private/var/* which symlinked of /var/*
3637
*/
37-
[, $expectedFilePathWithContentFilePath] = \explode('_temp_fixture_easy_testing', $expectedFilePathWithContent->getFilePath());
38-
[, $addedFilePathWithContentFilePath] = \explode('_temp_fixture_easy_testing', $addedFilePathWithContent->getFilePath());
38+
[, $expectedFilePathWithContentFilePath] = \explode(FixtureTempFileDumper::TEMP_FIXTURE_DIRECTORY, $expectedFilePathWithContent->getFilePath());
39+
[, $addedFilePathWithContentFilePath] = \explode(FixtureTempFileDumper::TEMP_FIXTURE_DIRECTORY, $addedFilePathWithContent->getFilePath());
3940
$this->assertSame($expectedFilePathWithContentFilePath, $addedFilePathWithContentFilePath);
4041
$this->assertSame($expectedFilePathWithContent->getFileContent(), $addedFilePathWithContent->getFileContent());
4142
}

src/Application/VersionResolver.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ final class VersionResolver
1717
* @api
1818
* @var string
1919
*/
20-
public const PACKAGE_VERSION = 'b01ea044294135d9ae9546939d66b8181af50940';
20+
public const PACKAGE_VERSION = '86ccf3f6854c78c6b7b06b8471d922724cb6542b';
2121
/**
2222
* @api
2323
* @var string
2424
*/
25-
public const RELEASE_DATE = '2022-08-30 14:59:35';
25+
public const RELEASE_DATE = '2022-08-30 16:15:10';
2626
/**
2727
* @var int
2828
*/

vendor/autoload.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@
99

1010
require_once __DIR__ . '/composer/autoload_real.php';
1111

12-
return ComposerAutoloaderInitedf27f069b71e894f79831b06b417de6::getLoader();
12+
return ComposerAutoloaderInitd0502117be6e6d45dc8ce25866585357::getLoader();

vendor/composer/autoload_classmap.php

+3
Original file line numberDiff line numberDiff line change
@@ -2703,6 +2703,9 @@
27032703
'Rector\\Symfony\\ValueObject\\ValidatorAssert\\ClassMethodAndAnnotation' => $vendorDir . '/rector/rector-symfony/src/ValueObject/ValidatorAssert/ClassMethodAndAnnotation.php',
27042704
'Rector\\Symfony\\ValueObject\\ValidatorAssert\\PropertyAndAnnotation' => $vendorDir . '/rector/rector-symfony/src/ValueObject/ValidatorAssert/PropertyAndAnnotation.php',
27052705
'Rector\\Testing\\Contract\\RectorTestInterface' => $baseDir . '/packages/Testing/Contract/RectorTestInterface.php',
2706+
'Rector\\Testing\\Fixture\\FixtureFileFinder' => $baseDir . '/packages/Testing/Fixture/FixtureFileFinder.php',
2707+
'Rector\\Testing\\Fixture\\FixtureSplitter' => $baseDir . '/packages/Testing/Fixture/FixtureSplitter.php',
2708+
'Rector\\Testing\\Fixture\\FixtureTempFileDumper' => $baseDir . '/packages/Testing/Fixture/FixtureTempFileDumper.php',
27062709
'Rector\\Testing\\PHPUnit\\AbstractRectorTestCase' => $baseDir . '/packages/Testing/PHPUnit/AbstractRectorTestCase.php',
27072710
'Rector\\Testing\\PHPUnit\\AbstractTestCase' => $baseDir . '/packages/Testing/PHPUnit/AbstractTestCase.php',
27082711
'Rector\\Testing\\PHPUnit\\Behavior\\MovingFilesTrait' => $baseDir . '/packages/Testing/PHPUnit/Behavior/MovingFilesTrait.php',

vendor/composer/autoload_real.php

+7-7
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
// autoload_real.php @generated by Composer
44

5-
class ComposerAutoloaderInitedf27f069b71e894f79831b06b417de6
5+
class ComposerAutoloaderInitd0502117be6e6d45dc8ce25866585357
66
{
77
private static $loader;
88

@@ -22,19 +22,19 @@ public static function getLoader()
2222
return self::$loader;
2323
}
2424

25-
spl_autoload_register(array('ComposerAutoloaderInitedf27f069b71e894f79831b06b417de6', 'loadClassLoader'), true, true);
25+
spl_autoload_register(array('ComposerAutoloaderInitd0502117be6e6d45dc8ce25866585357', 'loadClassLoader'), true, true);
2626
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(__DIR__));
27-
spl_autoload_unregister(array('ComposerAutoloaderInitedf27f069b71e894f79831b06b417de6', 'loadClassLoader'));
27+
spl_autoload_unregister(array('ComposerAutoloaderInitd0502117be6e6d45dc8ce25866585357', 'loadClassLoader'));
2828

2929
require __DIR__ . '/autoload_static.php';
30-
call_user_func(\Composer\Autoload\ComposerStaticInitedf27f069b71e894f79831b06b417de6::getInitializer($loader));
30+
call_user_func(\Composer\Autoload\ComposerStaticInitd0502117be6e6d45dc8ce25866585357::getInitializer($loader));
3131

3232
$loader->setClassMapAuthoritative(true);
3333
$loader->register(true);
3434

35-
$includeFiles = \Composer\Autoload\ComposerStaticInitedf27f069b71e894f79831b06b417de6::$files;
35+
$includeFiles = \Composer\Autoload\ComposerStaticInitd0502117be6e6d45dc8ce25866585357::$files;
3636
foreach ($includeFiles as $fileIdentifier => $file) {
37-
composerRequireedf27f069b71e894f79831b06b417de6($fileIdentifier, $file);
37+
composerRequired0502117be6e6d45dc8ce25866585357($fileIdentifier, $file);
3838
}
3939

4040
return $loader;
@@ -46,7 +46,7 @@ public static function getLoader()
4646
* @param string $file
4747
* @return void
4848
*/
49-
function composerRequireedf27f069b71e894f79831b06b417de6($fileIdentifier, $file)
49+
function composerRequired0502117be6e6d45dc8ce25866585357($fileIdentifier, $file)
5050
{
5151
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
5252
$GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;

vendor/composer/autoload_static.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
namespace Composer\Autoload;
66

7-
class ComposerStaticInitedf27f069b71e894f79831b06b417de6
7+
class ComposerStaticInitd0502117be6e6d45dc8ce25866585357
88
{
99
public static $files = array (
1010
'0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
@@ -2988,6 +2988,9 @@ class ComposerStaticInitedf27f069b71e894f79831b06b417de6
29882988
'Rector\\Symfony\\ValueObject\\ValidatorAssert\\ClassMethodAndAnnotation' => __DIR__ . '/..' . '/rector/rector-symfony/src/ValueObject/ValidatorAssert/ClassMethodAndAnnotation.php',
29892989
'Rector\\Symfony\\ValueObject\\ValidatorAssert\\PropertyAndAnnotation' => __DIR__ . '/..' . '/rector/rector-symfony/src/ValueObject/ValidatorAssert/PropertyAndAnnotation.php',
29902990
'Rector\\Testing\\Contract\\RectorTestInterface' => __DIR__ . '/../..' . '/packages/Testing/Contract/RectorTestInterface.php',
2991+
'Rector\\Testing\\Fixture\\FixtureFileFinder' => __DIR__ . '/../..' . '/packages/Testing/Fixture/FixtureFileFinder.php',
2992+
'Rector\\Testing\\Fixture\\FixtureSplitter' => __DIR__ . '/../..' . '/packages/Testing/Fixture/FixtureSplitter.php',
2993+
'Rector\\Testing\\Fixture\\FixtureTempFileDumper' => __DIR__ . '/../..' . '/packages/Testing/Fixture/FixtureTempFileDumper.php',
29912994
'Rector\\Testing\\PHPUnit\\AbstractRectorTestCase' => __DIR__ . '/../..' . '/packages/Testing/PHPUnit/AbstractRectorTestCase.php',
29922995
'Rector\\Testing\\PHPUnit\\AbstractTestCase' => __DIR__ . '/../..' . '/packages/Testing/PHPUnit/AbstractTestCase.php',
29932996
'Rector\\Testing\\PHPUnit\\Behavior\\MovingFilesTrait' => __DIR__ . '/../..' . '/packages/Testing/PHPUnit/Behavior/MovingFilesTrait.php',
@@ -3192,9 +3195,9 @@ class ComposerStaticInitedf27f069b71e894f79831b06b417de6
31923195
public static function getInitializer(ClassLoader $loader)
31933196
{
31943197
return \Closure::bind(function () use ($loader) {
3195-
$loader->prefixLengthsPsr4 = ComposerStaticInitedf27f069b71e894f79831b06b417de6::$prefixLengthsPsr4;
3196-
$loader->prefixDirsPsr4 = ComposerStaticInitedf27f069b71e894f79831b06b417de6::$prefixDirsPsr4;
3197-
$loader->classMap = ComposerStaticInitedf27f069b71e894f79831b06b417de6::$classMap;
3198+
$loader->prefixLengthsPsr4 = ComposerStaticInitd0502117be6e6d45dc8ce25866585357::$prefixLengthsPsr4;
3199+
$loader->prefixDirsPsr4 = ComposerStaticInitd0502117be6e6d45dc8ce25866585357::$prefixDirsPsr4;
3200+
$loader->classMap = ComposerStaticInitd0502117be6e6d45dc8ce25866585357::$classMap;
31983201

31993202
}, null, ClassLoader::class);
32003203
}

0 commit comments

Comments
 (0)