mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-03 09:50:49 +00:00
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:
parent
e7c028396b
commit
8f86f525f7
2
.github/workflows/build_scoped_rector.yaml
vendored
2
.github/workflows/build_scoped_rector.yaml
vendored
|
@ -100,7 +100,7 @@ jobs:
|
||||||
token: ${{ secrets.ACCESS_TOKEN }}
|
token: ${{ secrets.ACCESS_TOKEN }}
|
||||||
|
|
||||||
# remove remote files, to avoid piling up dead code in remote repository
|
# 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
|
- run: cp -a rector-prefixed-downgraded/. remote-repository
|
||||||
|
|
||||||
|
|
|
@ -124,7 +124,6 @@ PHP;
|
||||||
->notPath('#\/tests\/#')
|
->notPath('#\/tests\/#')
|
||||||
->notPath('#\/config\/#')
|
->notPath('#\/config\/#')
|
||||||
->notPath('#\/set\/#')
|
->notPath('#\/set\/#')
|
||||||
->in($vendorDir . '/symplify/symfony-php-config')
|
|
||||||
->sortByName();
|
->sortByName();
|
||||||
|
|
||||||
return iterator_to_array($finder->getIterator());
|
return iterator_to_array($finder->getIterator());
|
||||||
|
|
|
@ -13,7 +13,7 @@ use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigura
|
||||||
$phpStanStubLoader = new PHPStanStubLoader();
|
$phpStanStubLoader = new PHPStanStubLoader();
|
||||||
$phpStanStubLoader->loadStubs();
|
$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/EventDispatcher/EventSubscriberInterface.php';
|
||||||
require_once __DIR__ . '/../../stubs/Composer/Plugin/PluginInterface.php';
|
require_once __DIR__ . '/../../stubs/Composer/Plugin/PluginInterface.php';
|
||||||
require_once __DIR__ . '/../../stubs/Nette/DI/CompilerExtension.php';
|
require_once __DIR__ . '/../../stubs/Nette/DI/CompilerExtension.php';
|
||||||
|
|
|
@ -2,81 +2,68 @@
|
||||||
|
|
||||||
declare(strict_types = 1);
|
declare(strict_types = 1);
|
||||||
|
|
||||||
namespace
|
// inspired by https://github.com/phpstan/phpstan/blob/master/bootstrap.php
|
||||||
{
|
spl_autoload_register(function (string $class): void {
|
||||||
// inspired by https://github.com/phpstan/phpstan/blob/master/bootstrap.php
|
static $composerAutoloader;
|
||||||
spl_autoload_register(function (string $class): void {
|
|
||||||
static $composerAutoloader;
|
|
||||||
|
|
||||||
// already loaded in bin/rector.php
|
// already loaded in bin/rector.php
|
||||||
if (defined('__RECTOR_RUNNING__')) {
|
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;
|
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 {
|
public static function cases(): array;
|
||||||
/**
|
|
||||||
* @param int|string $value
|
|
||||||
* @return $this
|
|
||||||
*/
|
|
||||||
public static function from($value);
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param int|string $value
|
|
||||||
* @return $this|null
|
|
||||||
*/
|
|
||||||
public static function tryFrom($value);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// @see https://github.com/rectorphp/rector/issues/6531
|
if (! interface_exists('BackedEnum')) {
|
||||||
namespace PHPUnit\Framework
|
/**
|
||||||
{
|
* @since 8.1
|
||||||
if (! class_exists('PHPUnit\Framework\TestCase')) {
|
*/
|
||||||
abstract class TestCase
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,5 +48,9 @@ final class BootstrapFilesIncluder
|
||||||
throw new ShouldNotHappenException($errorMessage, $throwable->getCode(), $throwable);
|
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';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user