[NodeVisitor] make ReplaceDeprecatedConstant abstract

This commit is contained in:
TomasVotruba 2017-08-06 19:26:39 +02:00
parent a3dd2d7591
commit f8420008f3
8 changed files with 54 additions and 20 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -5,7 +5,6 @@ parameters:
services:
_defaults:
autowire: true
autoconfigure: true
# PSR-4 autodiscovery
Rector\:

View File

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

View File

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

View File

@ -0,0 +1,6 @@
services:
_defaults:
autowire: true
# tests
Rector\Tests\NodeVisitor\UpgradeDeprecation\ReplaceDeprecatedConstantNodeVisitor\ReplaceOldConstantNodeVisitor: ~