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
This commit is contained in:
Abdul Malik Ikhsan 2022-03-22 21:32:53 +07:00 committed by GitHub
parent e7c028396b
commit 8f86f525f7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 59 additions and 69 deletions

View File

@ -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

View File

@ -124,7 +124,6 @@ PHP;
->notPath('#\/tests\/#')
->notPath('#\/config\/#')
->notPath('#\/set\/#')
->in($vendorDir . '/symplify/symfony-php-config')
->sortByName();
return iterator_to_array($finder->getIterator());

View File

@ -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';

View File

@ -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);
}
}

View File

@ -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';
}
}
}