From 8f86f525f767f26787126265c158e8b9e77c4c0a Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Tue, 22 Mar 2022 21:32:53 +0700 Subject: [PATCH] Fix stub PHPUnit\Framework\TestCase (#1954) * Fix stub PHPUnit\Framework\TestCase * final touch: clean up * final touch: clean up * load after bootstrap loaded * move to target-repository * final touch: remove stubs-rector on remote-repository first when exists --- .github/workflows/build_scoped_rector.yaml | 2 +- build/build-preload.php | 1 - build/config/config-downgrade.php | 2 +- build/target-repository/bootstrap.php | 119 ++++++++---------- .../PHPUnit/Framework/TestCase.php | 0 src/Autoloading/BootstrapFilesIncluder.php | 4 + 6 files changed, 59 insertions(+), 69 deletions(-) rename {stubs-rector => build/target-repository/stubs-rector}/PHPUnit/Framework/TestCase.php (100%) diff --git a/.github/workflows/build_scoped_rector.yaml b/.github/workflows/build_scoped_rector.yaml index 731ca994521..57fef9580f1 100644 --- a/.github/workflows/build_scoped_rector.yaml +++ b/.github/workflows/build_scoped_rector.yaml @@ -100,7 +100,7 @@ jobs: token: ${{ secrets.ACCESS_TOKEN }} # remove remote files, to avoid piling up dead code in remote repository - - run: rm -rf remote-repository/.github remote-repository/e2e remote-repository/config remote-repository/src remote-repository/rules remote-repository/packages remote-repository/vendor + - run: rm -rf remote-repository/.github remote-repository/e2e remote-repository/config remote-repository/src remote-repository/rules remote-repository/packages remote-repository/vendor remote-repository/stubs-rector - run: cp -a rector-prefixed-downgraded/. remote-repository diff --git a/build/build-preload.php b/build/build-preload.php index 3c6f257a6a8..104d4fd944f 100755 --- a/build/build-preload.php +++ b/build/build-preload.php @@ -124,7 +124,6 @@ PHP; ->notPath('#\/tests\/#') ->notPath('#\/config\/#') ->notPath('#\/set\/#') - ->in($vendorDir . '/symplify/symfony-php-config') ->sortByName(); return iterator_to_array($finder->getIterator()); diff --git a/build/config/config-downgrade.php b/build/config/config-downgrade.php index fd65172fb44..cfba240d8ac 100644 --- a/build/config/config-downgrade.php +++ b/build/config/config-downgrade.php @@ -13,7 +13,7 @@ use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigura $phpStanStubLoader = new PHPStanStubLoader(); $phpStanStubLoader->loadStubs(); -require_once __DIR__ . '/../../stubs-rector/PHPUnit/Framework/TestCase.php'; +require_once __DIR__ . '/../target-repository/stubs-rector/PHPUnit/Framework/TestCase.php'; require_once __DIR__ . '/../../stubs/Composer/EventDispatcher/EventSubscriberInterface.php'; require_once __DIR__ . '/../../stubs/Composer/Plugin/PluginInterface.php'; require_once __DIR__ . '/../../stubs/Nette/DI/CompilerExtension.php'; diff --git a/build/target-repository/bootstrap.php b/build/target-repository/bootstrap.php index b6c54466fff..9b2b440a270 100644 --- a/build/target-repository/bootstrap.php +++ b/build/target-repository/bootstrap.php @@ -2,81 +2,68 @@ declare(strict_types = 1); -namespace -{ - // inspired by https://github.com/phpstan/phpstan/blob/master/bootstrap.php - spl_autoload_register(function (string $class): void { - static $composerAutoloader; +// inspired by https://github.com/phpstan/phpstan/blob/master/bootstrap.php +spl_autoload_register(function (string $class): void { + static $composerAutoloader; - // already loaded in bin/rector.php - if (defined('__RECTOR_RUNNING__')) { + // already loaded in bin/rector.php + if (defined('__RECTOR_RUNNING__')) { + return; + } + + // load prefixed or native class, e.g. for running tests + if (strpos($class, 'RectorPrefix') === 0 || strpos($class, 'Rector\\') === 0) { + if ($composerAutoloader === null) { + // prefixed version autoload + $composerAutoloader = require __DIR__ . '/vendor/autoload.php'; + } + $composerAutoloader->loadClass($class); + } + + // aliased by php-scoper, that's why its missing + if ($class === 'Symplify\SmartFileSystem\SmartFileInfo') { + $filePath = __DIR__ . '/vendor/symplify/smart-file-system/src/SmartFileInfo.php'; + if (file_exists($filePath)) { + require $filePath; + } + } + + if ($class === 'Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator') { + // avoid duplicated autoload bug in Rector demo runner + if (class_exists('Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator', false)) { return; } - - // load prefixed or native class, e.g. for running tests - if (strpos($class, 'RectorPrefix') === 0 || strpos($class, 'Rector\\') === 0) { - if ($composerAutoloader === null) { - // prefixed version autoload - $composerAutoloader = require __DIR__ . '/vendor/autoload.php'; - } - $composerAutoloader->loadClass($class); - } - - // aliased by php-scoper, that's why its missing - if ($class === 'Symplify\SmartFileSystem\SmartFileInfo') { - $filePath = __DIR__ . '/vendor/symplify/smart-file-system/src/SmartFileInfo.php'; - if (file_exists($filePath)) { - require $filePath; - } - } - - if ($class === 'Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator') { - // avoid duplicated autoload bug in Rector demo runner - if (class_exists('Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator', false)) { - return; - } - } - }); - - if (! interface_exists('UnitEnum')) { - /** - * @since 8.1 - */ - interface UnitEnum - { - /** - * @return static[] - */ - public static function cases(): array; - } } +}); - if (! interface_exists('BackedEnum')) { +if (! interface_exists('UnitEnum')) { + /** + * @since 8.1 + */ + interface UnitEnum + { /** - * @since 8.1 + * @return static[] */ - interface BackedEnum extends UnitEnum { - /** - * @param int|string $value - * @return $this - */ - public static function from($value); - - /** - * @param int|string $value - * @return $this|null - */ - public static function tryFrom($value); - } + public static function cases(): array; } } -// @see https://github.com/rectorphp/rector/issues/6531 -namespace PHPUnit\Framework -{ - if (! class_exists('PHPUnit\Framework\TestCase')) { - abstract class TestCase - { - } +if (! interface_exists('BackedEnum')) { + /** + * @since 8.1 + */ + interface BackedEnum extends UnitEnum { + /** + * @param int|string $value + * @return $this + */ + public static function from($value); + + /** + * @param int|string $value + * @return $this|null + */ + public static function tryFrom($value); } } diff --git a/stubs-rector/PHPUnit/Framework/TestCase.php b/build/target-repository/stubs-rector/PHPUnit/Framework/TestCase.php similarity index 100% rename from stubs-rector/PHPUnit/Framework/TestCase.php rename to build/target-repository/stubs-rector/PHPUnit/Framework/TestCase.php diff --git a/src/Autoloading/BootstrapFilesIncluder.php b/src/Autoloading/BootstrapFilesIncluder.php index 1445df1a7e2..d6af3a5870b 100644 --- a/src/Autoloading/BootstrapFilesIncluder.php +++ b/src/Autoloading/BootstrapFilesIncluder.php @@ -48,5 +48,9 @@ final class BootstrapFilesIncluder throw new ShouldNotHappenException($errorMessage, $throwable->getCode(), $throwable); } } + + if (is_file(__DIR__ . '/../../stubs-rector/PHPUnit/Framework/TestCase.php')) { + require_once __DIR__ . '/../../stubs-rector/PHPUnit/Framework/TestCase.php'; + } } }