mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-01 00:40:52 +00:00
[NodeVisitor] make ReplaceDeprecatedConstant abstract
This commit is contained in:
parent
a3dd2d7591
commit
f8420008f3
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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:
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ parameters:
|
|||
services:
|
||||
_defaults:
|
||||
autowire: true
|
||||
autoconfigure: true
|
||||
|
||||
# PSR-4 autodiscovery
|
||||
Rector\:
|
||||
|
|
|
@ -0,0 +1,23 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\NodeVisitor\UpgradeDeprecation\ReplaceDeprecatedConstantNodeVisitor;
|
||||
|
||||
use Rector\NodeVisitor\UpgradeDeprecation\AbstraceReplaceDeprecatedConstantNodeVisitor;
|
||||
|
||||
final class ReplaceOldConstantNodeVisitor extends AbstraceReplaceDeprecatedConstantNodeVisitor
|
||||
{
|
||||
public function getClassName(): string
|
||||
{
|
||||
return'ClassWithConstants';
|
||||
}
|
||||
|
||||
public function getOldConstantName(): string
|
||||
{
|
||||
return 'OLD_CONSTANT';
|
||||
}
|
||||
|
||||
public function getNewConstantName(): string
|
||||
{
|
||||
return 'NEW_CONSTANT';
|
||||
}
|
||||
}
|
|
@ -1,6 +1,6 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\NodeVisitor\ReplaceDeprecatedConstantNodeVisitor\InjectAnnotationToConstructorReconstructor;
|
||||
namespace Rector\Tests\NodeVisitor\UpgradeDeprecation\ReplaceDeprecatedConstantNodeVisitor;
|
||||
|
||||
use Rector\Testing\PHPUnit\AbstractReconstructorTestCase;
|
||||
|
||||
|
|
6
tests/config/services.yml
Normal file
6
tests/config/services.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
services:
|
||||
_defaults:
|
||||
autowire: true
|
||||
|
||||
# tests
|
||||
Rector\Tests\NodeVisitor\UpgradeDeprecation\ReplaceDeprecatedConstantNodeVisitor\ReplaceOldConstantNodeVisitor: ~
|
Loading…
Reference in New Issue
Block a user