diff --git a/src/DependencyInjection/AppKernel.php b/src/DependencyInjection/AppKernel.php index a5206e86e43..8b9414a2166 100644 --- a/src/DependencyInjection/AppKernel.php +++ b/src/DependencyInjection/AppKernel.php @@ -10,14 +10,24 @@ use Symfony\Component\HttpKernel\Kernel; final class AppKernel extends Kernel { - public function __construct() + /** + * @var string + */ + private $config; + + public function __construct(?string $config = '') { + $this->config = $config; parent::__construct('dev', true); } public function registerContainerConfiguration(LoaderInterface $loader): void { $loader->load(__DIR__ . '/../config/services.yml'); + + if ($this->config) { + $loader->load($this->config); + } } public function getCacheDir(): string diff --git a/src/DependencyInjection/ContainerFactory.php b/src/DependencyInjection/ContainerFactory.php index ab7893626f3..690fd12c594 100644 --- a/src/DependencyInjection/ContainerFactory.php +++ b/src/DependencyInjection/ContainerFactory.php @@ -13,4 +13,12 @@ final class ContainerFactory return $appKernel->getContainer(); } + + public function createWithConfig(string $config): ContainerInterface + { + $appKernel = new AppKernel($config); + $appKernel->boot(); + + return $appKernel->getContainer(); + } } diff --git a/src/NodeVisitor/UpgradeDeprecation/ReplaceDeprecatedConstantNodeVisitor.php b/src/NodeVisitor/UpgradeDeprecation/AbstraceReplaceDeprecatedConstantNodeVisitor.php similarity index 77% rename from src/NodeVisitor/UpgradeDeprecation/ReplaceDeprecatedConstantNodeVisitor.php rename to src/NodeVisitor/UpgradeDeprecation/AbstraceReplaceDeprecatedConstantNodeVisitor.php index b745948c6aa..013a6ba0a1d 100644 --- a/src/NodeVisitor/UpgradeDeprecation/ReplaceDeprecatedConstantNodeVisitor.php +++ b/src/NodeVisitor/UpgradeDeprecation/AbstraceReplaceDeprecatedConstantNodeVisitor.php @@ -7,24 +7,13 @@ use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\NodeTraverser; use PhpParser\NodeVisitorAbstract; -final class ReplaceDeprecatedConstantNodeVisitor extends NodeVisitorAbstract +abstract class AbstraceReplaceDeprecatedConstantNodeVisitor extends NodeVisitorAbstract { - // this will be in specific node visitor, now hardcoded + abstract public function getClassName(): string; - public function getClassName(): string - { - return'ClassWithConstants'; - } + abstract public function getOldConstantName(): string; - public function getOldConstantName(): string - { - return 'OLD_CONSTANT'; - } - - public function getNewConstantName(): string - { - return 'NEW_CONSTANT'; - } + abstract public function getNewConstantName(): string; /** * Return value semantics: diff --git a/src/Testing/PHPUnit/AbstractReconstructorTestCase.php b/src/Testing/PHPUnit/AbstractReconstructorTestCase.php index 5014fa3e7f6..f3dcce41136 100644 --- a/src/Testing/PHPUnit/AbstractReconstructorTestCase.php +++ b/src/Testing/PHPUnit/AbstractReconstructorTestCase.php @@ -2,7 +2,6 @@ namespace Rector\Testing\PHPUnit; -use PhpParser\NodeVisitor; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; use Rector\DependencyInjection\ContainerFactory; @@ -23,7 +22,7 @@ abstract class AbstractReconstructorTestCase extends TestCase protected function setUp(): void { - $this->container = (new ContainerFactory)->create(); + $this->container = (new ContainerFactory)->createWithConfig(__DIR__ . '/../../../tests/config/services.yml'); $this->fileReconstructor = $this->container->get(FileReconstructor::class); } diff --git a/src/config/services.yml b/src/config/services.yml index 526168dd2ed..3642becdbe5 100644 --- a/src/config/services.yml +++ b/src/config/services.yml @@ -5,7 +5,6 @@ parameters: services: _defaults: autowire: true - autoconfigure: true # PSR-4 autodiscovery Rector\: diff --git a/tests/NodeVisitor/UpgradeDeprecation/ReplaceDeprecatedConstantNodeVisitor/ReplaceOldConstantNodeVisitor.php b/tests/NodeVisitor/UpgradeDeprecation/ReplaceDeprecatedConstantNodeVisitor/ReplaceOldConstantNodeVisitor.php new file mode 100644 index 00000000000..0c44d5f8cf5 --- /dev/null +++ b/tests/NodeVisitor/UpgradeDeprecation/ReplaceDeprecatedConstantNodeVisitor/ReplaceOldConstantNodeVisitor.php @@ -0,0 +1,23 @@ +