mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-09 12:42:38 +00:00
Updated Rector to commit c2acf79190
c2acf79190
Added test for Rectors making additional changes (#545)
This commit is contained in:
parent
ed866c99db
commit
cedca442f9
|
@ -18,6 +18,7 @@ use Rector\Core\ValueObject\Application\File;
|
|||
use Rector\NodeTypeResolver\Reflection\BetterReflection\SourceLocatorProvider\DynamicSourceLocatorProvider;
|
||||
use Rector\Testing\Contract\RectorTestInterface;
|
||||
use Rector\Testing\PHPUnit\Behavior\MovingFilesTrait;
|
||||
use Rector\Testing\PHPUnit\Behavior\MultipleFilesChangedTrait;
|
||||
use RectorPrefix20210806\Symplify\EasyTesting\DataProvider\StaticFixtureFinder;
|
||||
use RectorPrefix20210806\Symplify\EasyTesting\DataProvider\StaticFixtureUpdater;
|
||||
use RectorPrefix20210806\Symplify\EasyTesting\StaticFixtureSplitter;
|
||||
|
@ -26,6 +27,7 @@ use Symplify\SmartFileSystem\SmartFileInfo;
|
|||
abstract class AbstractRectorTestCase extends \Rector\Testing\PHPUnit\AbstractTestCase implements \Rector\Testing\Contract\RectorTestInterface
|
||||
{
|
||||
use MovingFilesTrait;
|
||||
use MultipleFilesChangedTrait;
|
||||
/**
|
||||
* @var \Symplify\PackageBuilder\Parameter\ParameterProvider
|
||||
*/
|
||||
|
|
|
@ -0,0 +1,85 @@
|
|||
<?php
|
||||
|
||||
declare (strict_types=1);
|
||||
namespace Rector\Testing\PHPUnit\Behavior;
|
||||
|
||||
use Rector\Core\Exception\ShouldNotHappenException;
|
||||
use Symplify\SmartFileSystem\SmartFileInfo;
|
||||
trait MultipleFilesChangedTrait
|
||||
{
|
||||
/**
|
||||
* @param \Symplify\SmartFileSystem\SmartFileInfo $fixtureFileInfo
|
||||
* @param bool $allowMatches
|
||||
*/
|
||||
protected function doTestFileInfoWithAdditionalChanges($fixtureFileInfo, $allowMatches = \true) : void
|
||||
{
|
||||
$separator = '-----';
|
||||
[$originalContent, $expectedContent, $additionalInfo] = \explode($separator, $fixtureFileInfo->getContents(), 3);
|
||||
$additionalChanges = \explode($separator, $additionalInfo);
|
||||
/** @var array<array{0: ?string, 1: ?string, 2: ?string}> $additionalFileChanges */
|
||||
$additionalFileChanges = \array_chunk($additionalChanges, 3);
|
||||
$expectedFileChanges = $this->prepareAdditionalChangedFiles($additionalFileChanges);
|
||||
$fixturePath = $this->getFixtureTempDirectory() . '/' . $fixtureFileInfo->getFilename();
|
||||
$this->createFixtureDir($fixturePath);
|
||||
$fixtureContent = $originalContent;
|
||||
if (\trim($expectedContent)) {
|
||||
$fixtureContent .= $separator . $expectedContent;
|
||||
}
|
||||
\file_put_contents($fixturePath, $fixtureContent);
|
||||
$newFileInfo = new \Symplify\SmartFileSystem\SmartFileInfo($fixturePath);
|
||||
$this->doTestFileInfo($newFileInfo, $allowMatches);
|
||||
$this->checkAdditionalChanges($expectedFileChanges);
|
||||
if (\file_exists($fixturePath)) {
|
||||
\unlink($fixturePath);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* @param array<array{0: ?string, 1: ?string, 2: ?string}> $additionalFileChanges
|
||||
* @return array<string, string>
|
||||
*/
|
||||
private function prepareAdditionalChangedFiles(array $additionalFileChanges) : array
|
||||
{
|
||||
$expectedFileChanges = [];
|
||||
foreach ($additionalFileChanges as $additionalFileChange) {
|
||||
$path = isset($additionalFileChange[0]) ? \trim($additionalFileChange[0]) : null;
|
||||
if ($path === null) {
|
||||
throw new \Rector\Core\Exception\ShouldNotHappenException('Path for additional change must be set');
|
||||
}
|
||||
$fullPath = $this->getFixtureTempDirectory() . '/' . $path;
|
||||
$input = isset($additionalFileChange[1]) ? \trim($additionalFileChange[1]) : null;
|
||||
if ($input) {
|
||||
$this->createFixtureDir($fullPath);
|
||||
\file_put_contents($fullPath, $input);
|
||||
}
|
||||
$expectedFileChanges[$fullPath] = isset($additionalFileChange[2]) ? \trim($additionalFileChange[2]) : '';
|
||||
}
|
||||
return $expectedFileChanges;
|
||||
}
|
||||
/**
|
||||
* @param array<string, string> $expectedFileChanges
|
||||
*/
|
||||
private function checkAdditionalChanges(array $expectedFileChanges) : void
|
||||
{
|
||||
$addedFilesWithContent = $this->removedAndAddedFilesCollector->getAddedFilesWithContent();
|
||||
$addedFiles = [];
|
||||
foreach ($addedFilesWithContent as $addedFileWithContent) {
|
||||
$addedFiles[$addedFileWithContent->getFilePath()] = $addedFileWithContent;
|
||||
}
|
||||
foreach ($expectedFileChanges as $path => $expectedFileChange) {
|
||||
$addedFile = $addedFiles[$path] ?? null;
|
||||
$this->assertSame($path, $addedFile ? $addedFile->getFilePath() : null);
|
||||
$realFileContent = $addedFile ? \trim($addedFile->getFileContent()) : null;
|
||||
$this->assertSame($expectedFileChange, $realFileContent);
|
||||
if (\file_exists($path)) {
|
||||
\unlink($path);
|
||||
}
|
||||
}
|
||||
}
|
||||
private function createFixtureDir(string $fileName) : void
|
||||
{
|
||||
$dirName = \dirname($fileName);
|
||||
if (!\file_exists($dirName)) {
|
||||
\mkdir($dirName, 0777, \true);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,11 +16,11 @@ final class VersionResolver
|
|||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PACKAGE_VERSION = '7398a6637c49cd6f329d27a37f5006a69c219924';
|
||||
public const PACKAGE_VERSION = 'c2acf79190949005a21fbacae74ba08a740d4058';
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const RELEASE_DATE = '2021-08-06 08:35:13';
|
||||
public const RELEASE_DATE = '2021-08-06 08:39:47';
|
||||
public static function resolvePackageVersion() : string
|
||||
{
|
||||
$process = new \RectorPrefix20210806\Symfony\Component\Process\Process(['git', 'log', '--pretty="%H"', '-n1', 'HEAD'], __DIR__);
|
||||
|
|
2
vendor/autoload.php
vendored
2
vendor/autoload.php
vendored
|
@ -4,4 +4,4 @@
|
|||
|
||||
require_once __DIR__ . '/composer/autoload_real.php';
|
||||
|
||||
return ComposerAutoloaderInit180724a706c642e1ae3013ee5854258b::getLoader();
|
||||
return ComposerAutoloaderInit023a10cf85b690bf9054bda8136dfcef::getLoader();
|
||||
|
|
1
vendor/composer/autoload_classmap.php
vendored
1
vendor/composer/autoload_classmap.php
vendored
|
@ -3026,6 +3026,7 @@ return array(
|
|||
'Rector\\Testing\\PHPUnit\\AbstractRectorTestCase' => $baseDir . '/packages/Testing/PHPUnit/AbstractRectorTestCase.php',
|
||||
'Rector\\Testing\\PHPUnit\\AbstractTestCase' => $baseDir . '/packages/Testing/PHPUnit/AbstractTestCase.php',
|
||||
'Rector\\Testing\\PHPUnit\\Behavior\\MovingFilesTrait' => $baseDir . '/packages/Testing/PHPUnit/Behavior/MovingFilesTrait.php',
|
||||
'Rector\\Testing\\PHPUnit\\Behavior\\MultipleFilesChangedTrait' => $baseDir . '/packages/Testing/PHPUnit/Behavior/MultipleFilesChangedTrait.php',
|
||||
'Rector\\Testing\\PHPUnit\\StaticPHPUnitEnvironment' => $baseDir . '/packages/Testing/PHPUnit/StaticPHPUnitEnvironment.php',
|
||||
'Rector\\Testing\\TestingParser\\TestingParser' => $baseDir . '/packages/Testing/TestingParser/TestingParser.php',
|
||||
'Rector\\Testing\\ValueObject\\InputFilePathWithExpectedFile' => $baseDir . '/packages/Testing/ValueObject/InputFilePathWithExpectedFile.php',
|
||||
|
|
14
vendor/composer/autoload_real.php
vendored
14
vendor/composer/autoload_real.php
vendored
|
@ -2,7 +2,7 @@
|
|||
|
||||
// autoload_real.php @generated by Composer
|
||||
|
||||
class ComposerAutoloaderInit180724a706c642e1ae3013ee5854258b
|
||||
class ComposerAutoloaderInit023a10cf85b690bf9054bda8136dfcef
|
||||
{
|
||||
private static $loader;
|
||||
|
||||
|
@ -22,15 +22,15 @@ class ComposerAutoloaderInit180724a706c642e1ae3013ee5854258b
|
|||
return self::$loader;
|
||||
}
|
||||
|
||||
spl_autoload_register(array('ComposerAutoloaderInit180724a706c642e1ae3013ee5854258b', 'loadClassLoader'), true, true);
|
||||
spl_autoload_register(array('ComposerAutoloaderInit023a10cf85b690bf9054bda8136dfcef', 'loadClassLoader'), true, true);
|
||||
self::$loader = $loader = new \Composer\Autoload\ClassLoader(\dirname(\dirname(__FILE__)));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit180724a706c642e1ae3013ee5854258b', 'loadClassLoader'));
|
||||
spl_autoload_unregister(array('ComposerAutoloaderInit023a10cf85b690bf9054bda8136dfcef', 'loadClassLoader'));
|
||||
|
||||
$useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
|
||||
if ($useStaticLoader) {
|
||||
require __DIR__ . '/autoload_static.php';
|
||||
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit180724a706c642e1ae3013ee5854258b::getInitializer($loader));
|
||||
call_user_func(\Composer\Autoload\ComposerStaticInit023a10cf85b690bf9054bda8136dfcef::getInitializer($loader));
|
||||
} else {
|
||||
$classMap = require __DIR__ . '/autoload_classmap.php';
|
||||
if ($classMap) {
|
||||
|
@ -42,19 +42,19 @@ class ComposerAutoloaderInit180724a706c642e1ae3013ee5854258b
|
|||
$loader->register(true);
|
||||
|
||||
if ($useStaticLoader) {
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInit180724a706c642e1ae3013ee5854258b::$files;
|
||||
$includeFiles = Composer\Autoload\ComposerStaticInit023a10cf85b690bf9054bda8136dfcef::$files;
|
||||
} else {
|
||||
$includeFiles = require __DIR__ . '/autoload_files.php';
|
||||
}
|
||||
foreach ($includeFiles as $fileIdentifier => $file) {
|
||||
composerRequire180724a706c642e1ae3013ee5854258b($fileIdentifier, $file);
|
||||
composerRequire023a10cf85b690bf9054bda8136dfcef($fileIdentifier, $file);
|
||||
}
|
||||
|
||||
return $loader;
|
||||
}
|
||||
}
|
||||
|
||||
function composerRequire180724a706c642e1ae3013ee5854258b($fileIdentifier, $file)
|
||||
function composerRequire023a10cf85b690bf9054bda8136dfcef($fileIdentifier, $file)
|
||||
{
|
||||
if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
|
||||
require $file;
|
||||
|
|
9
vendor/composer/autoload_static.php
vendored
9
vendor/composer/autoload_static.php
vendored
|
@ -4,7 +4,7 @@
|
|||
|
||||
namespace Composer\Autoload;
|
||||
|
||||
class ComposerStaticInit180724a706c642e1ae3013ee5854258b
|
||||
class ComposerStaticInit023a10cf85b690bf9054bda8136dfcef
|
||||
{
|
||||
public static $files = array (
|
||||
'a4a119a56e50fbb293281d9a48007e0e' => __DIR__ . '/..' . '/symfony/polyfill-php80/bootstrap.php',
|
||||
|
@ -3386,6 +3386,7 @@ class ComposerStaticInit180724a706c642e1ae3013ee5854258b
|
|||
'Rector\\Testing\\PHPUnit\\AbstractRectorTestCase' => __DIR__ . '/../..' . '/packages/Testing/PHPUnit/AbstractRectorTestCase.php',
|
||||
'Rector\\Testing\\PHPUnit\\AbstractTestCase' => __DIR__ . '/../..' . '/packages/Testing/PHPUnit/AbstractTestCase.php',
|
||||
'Rector\\Testing\\PHPUnit\\Behavior\\MovingFilesTrait' => __DIR__ . '/../..' . '/packages/Testing/PHPUnit/Behavior/MovingFilesTrait.php',
|
||||
'Rector\\Testing\\PHPUnit\\Behavior\\MultipleFilesChangedTrait' => __DIR__ . '/../..' . '/packages/Testing/PHPUnit/Behavior/MultipleFilesChangedTrait.php',
|
||||
'Rector\\Testing\\PHPUnit\\StaticPHPUnitEnvironment' => __DIR__ . '/../..' . '/packages/Testing/PHPUnit/StaticPHPUnitEnvironment.php',
|
||||
'Rector\\Testing\\TestingParser\\TestingParser' => __DIR__ . '/../..' . '/packages/Testing/TestingParser/TestingParser.php',
|
||||
'Rector\\Testing\\ValueObject\\InputFilePathWithExpectedFile' => __DIR__ . '/../..' . '/packages/Testing/ValueObject/InputFilePathWithExpectedFile.php',
|
||||
|
@ -3847,9 +3848,9 @@ class ComposerStaticInit180724a706c642e1ae3013ee5854258b
|
|||
public static function getInitializer(ClassLoader $loader)
|
||||
{
|
||||
return \Closure::bind(function () use ($loader) {
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit180724a706c642e1ae3013ee5854258b::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit180724a706c642e1ae3013ee5854258b::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit180724a706c642e1ae3013ee5854258b::$classMap;
|
||||
$loader->prefixLengthsPsr4 = ComposerStaticInit023a10cf85b690bf9054bda8136dfcef::$prefixLengthsPsr4;
|
||||
$loader->prefixDirsPsr4 = ComposerStaticInit023a10cf85b690bf9054bda8136dfcef::$prefixDirsPsr4;
|
||||
$loader->classMap = ComposerStaticInit023a10cf85b690bf9054bda8136dfcef::$classMap;
|
||||
|
||||
}, null, ClassLoader::class);
|
||||
}
|
||||
|
|
10
vendor/scoper-autoload.php
vendored
10
vendor/scoper-autoload.php
vendored
|
@ -9,8 +9,8 @@ $loader = require_once __DIR__.'/autoload.php';
|
|||
if (!class_exists('AutoloadIncluder', false) && !interface_exists('AutoloadIncluder', false) && !trait_exists('AutoloadIncluder', false)) {
|
||||
spl_autoload_call('RectorPrefix20210806\AutoloadIncluder');
|
||||
}
|
||||
if (!class_exists('ComposerAutoloaderInit180724a706c642e1ae3013ee5854258b', false) && !interface_exists('ComposerAutoloaderInit180724a706c642e1ae3013ee5854258b', false) && !trait_exists('ComposerAutoloaderInit180724a706c642e1ae3013ee5854258b', false)) {
|
||||
spl_autoload_call('RectorPrefix20210806\ComposerAutoloaderInit180724a706c642e1ae3013ee5854258b');
|
||||
if (!class_exists('ComposerAutoloaderInit023a10cf85b690bf9054bda8136dfcef', false) && !interface_exists('ComposerAutoloaderInit023a10cf85b690bf9054bda8136dfcef', false) && !trait_exists('ComposerAutoloaderInit023a10cf85b690bf9054bda8136dfcef', false)) {
|
||||
spl_autoload_call('RectorPrefix20210806\ComposerAutoloaderInit023a10cf85b690bf9054bda8136dfcef');
|
||||
}
|
||||
if (!class_exists('AjaxLogin', false) && !interface_exists('AjaxLogin', false) && !trait_exists('AjaxLogin', false)) {
|
||||
spl_autoload_call('RectorPrefix20210806\AjaxLogin');
|
||||
|
@ -3305,9 +3305,9 @@ if (!function_exists('print_node')) {
|
|||
return \RectorPrefix20210806\print_node(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('composerRequire180724a706c642e1ae3013ee5854258b')) {
|
||||
function composerRequire180724a706c642e1ae3013ee5854258b() {
|
||||
return \RectorPrefix20210806\composerRequire180724a706c642e1ae3013ee5854258b(...func_get_args());
|
||||
if (!function_exists('composerRequire023a10cf85b690bf9054bda8136dfcef')) {
|
||||
function composerRequire023a10cf85b690bf9054bda8136dfcef() {
|
||||
return \RectorPrefix20210806\composerRequire023a10cf85b690bf9054bda8136dfcef(...func_get_args());
|
||||
}
|
||||
}
|
||||
if (!function_exists('parseArgs')) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user