mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-06 03:10:50 +00:00
Merge pull request #26 from TomasVotruba/phpunit-parent-class-rector
[PHPUnit] add TestCase class rector
This commit is contained in:
commit
33679cf897
|
@ -2,6 +2,9 @@
|
|||
|
||||
namespace Rector\Deprecation;
|
||||
|
||||
/**
|
||||
* @todo split to make SOLID
|
||||
*/
|
||||
final class SetNames
|
||||
{
|
||||
/**
|
||||
|
@ -18,4 +21,14 @@ final class SetNames
|
|||
* @var string
|
||||
*/
|
||||
public const SYMFONY_EXTRA = 'SymfonyExtra';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PHPUNIT = 'PHPUnit';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public const PHP_CODE_SNIFER = 'PHP_CodeSniffer';
|
||||
}
|
||||
|
|
29
src/Rector/Contrib/PHPUnit/NamespaceClassRector.php
Normal file
29
src/Rector/Contrib/PHPUnit/NamespaceClassRector.php
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Rector\Contrib\PHPUnit;
|
||||
|
||||
use Rector\Deprecation\SetNames;
|
||||
use Rector\Rector\AbstractClassReplacerRector;
|
||||
|
||||
final class NamespaceClassRector extends AbstractClassReplacerRector
|
||||
{
|
||||
public function getSetName(): string
|
||||
{
|
||||
return SetNames::PHPUNIT;
|
||||
}
|
||||
|
||||
public function sinceVersion(): float
|
||||
{
|
||||
return 6.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getOldToNewClasses(): array
|
||||
{
|
||||
return [
|
||||
'PHPUnit_Framework_TestCase' => 'PHPUnit\Framework\TestCase',
|
||||
];
|
||||
}
|
||||
}
|
29
src/Rector/Contrib/PHP_CodeSniffer/NamespaceClassRector.php
Normal file
29
src/Rector/Contrib/PHP_CodeSniffer/NamespaceClassRector.php
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Rector\Contrib\PHP_CodeSniffer;
|
||||
|
||||
use Rector\Deprecation\SetNames;
|
||||
use Rector\Rector\AbstractClassReplacerRector;
|
||||
|
||||
final class NamespaceClassRector extends AbstractClassReplacerRector
|
||||
{
|
||||
public function getSetName(): string
|
||||
{
|
||||
return SetNames::PHP_CODE_SNIFER;
|
||||
}
|
||||
|
||||
public function sinceVersion(): float
|
||||
{
|
||||
return 3.0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getOldToNewClasses(): array
|
||||
{
|
||||
return [
|
||||
'PHP_CodeSniffer_Sniffs_Sniff' => 'PHP_CodeSniffer\Sniffs\Sniff',
|
||||
];
|
||||
}
|
||||
}
|
|
@ -28,8 +28,13 @@ final class FrameworkBundleClassReplacementsRector extends AbstractClassReplacer
|
|||
protected function getOldToNewClasses(): array
|
||||
{
|
||||
return [
|
||||
'Symfony\Bundle\FrameworkBundle\DependencyInjectino\Compiler\SerializerPass' => 'Symfony\Component\Serializer\DependencyInjection\SerializerPass',
|
||||
// @todo: complete the rest
|
||||
'Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\AddConsoleCommandPass' => 'Symfony\Component\Console\DependencyInjection\AddConsoleCommandPass',
|
||||
'Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\SerializerPass' => 'Symfony\Component\Serializer\DependencyInjection\SerializerPass',
|
||||
'Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\FormPass' => 'Symfony\Component\Form\DependencyInjection\FormPass',
|
||||
'Symfony\Bundle\FrameworkBundle\EventListener\SessionListener' => 'Symfony\Component\HttpKernel\EventListener\SessionListener',
|
||||
'Symfony\Bundle\FrameworkBundle\EventListener\TestSessionListener' => 'Symfony\Component\HttpKernel\EventListener\TestSessionListener',
|
||||
'Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\ConfigCachePass' => 'Symfony\Component\Config\DependencyInjection\ConfigCachePass',
|
||||
'Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\PropertyInfoPass' => 'Symfony\Component\PropertyInfo\DependencyInjection\PropertyInfoPass',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ namespace Rector\Rector\Contrib\SymfonyExtra;
|
|||
use Nette\Utils\Strings;
|
||||
use PhpParser\Node;
|
||||
use PhpParser\Node\Expr\MethodCall;
|
||||
use PhpParser\Node\Name;
|
||||
use PhpParser\Node\Name\FullyQualified;
|
||||
use Rector\Builder\Class_\ClassPropertyCollector;
|
||||
use Rector\Builder\Kernel\ServiceFromKernelResolver;
|
||||
use Rector\Builder\Naming\NameResolver;
|
||||
|
@ -18,9 +18,6 @@ use Rector\Tests\Rector\Contrib\SymfonyExtra\GetterToPropertyRector\Source\Local
|
|||
/**
|
||||
* Ref: https://github.com/symfony/symfony/blob/master/UPGRADE-4.0.md#console
|
||||
*
|
||||
* Similar to @see \Rector\Rector\Contrib\Symfony\GetterToPropertyRector
|
||||
* @todo Extract common logic!
|
||||
*
|
||||
* Before:
|
||||
* class MyCommand extends ContainerAwareCommand
|
||||
*
|
||||
|
@ -126,6 +123,6 @@ final class CommandToConstructorInjectionRector extends AbstractRector
|
|||
|
||||
private function replaceParentContainerAwareCommandWithCommand(): void
|
||||
{
|
||||
$this->classNode->extends = new Name('\Symfony\Component\Console\Command\Command');
|
||||
$this->classNode->extends = new FullyQualified('Symfony\Component\Console\Command\Command');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
<?php declare (strict_types=1);
|
||||
|
||||
class MyTest extends \PHPUnit\Framework\TestCase
|
||||
{
|
||||
}
|
25
tests/Rector/Contrib/PHPUnit/NamespaceClassRector/Test.php
Normal file
25
tests/Rector/Contrib/PHPUnit/NamespaceClassRector/Test.php
Normal file
|
@ -0,0 +1,25 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Rector\Contrib\PHPUnit\NamespaceClassRector;
|
||||
|
||||
use Rector\Rector\Contrib\PHPUnit\NamespaceClassRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
|
||||
final class Test extends AbstractRectorTestCase
|
||||
{
|
||||
public function test(): void
|
||||
{
|
||||
$this->doTestFileMatchesExpectedContent(
|
||||
__DIR__ . '/Wrong/wrong.php.inc',
|
||||
__DIR__ . '/Correct/correct.php.inc'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getRectorClasses(): array
|
||||
{
|
||||
return [NamespaceClassRector::class];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
<?php declare (strict_types=1);
|
||||
|
||||
class MyTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
<?php declare (strict_types=1);
|
||||
|
||||
class Sniff implements \PHP_CodeSniffer\Sniffs\Sniff
|
||||
{
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Tests\Rector\Contrib\PHP_CodeSniffer\NamespaceClassRector;
|
||||
|
||||
use Rector\Rector\Contrib\PHP_CodeSniffer\NamespaceClassRector;
|
||||
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
|
||||
|
||||
final class Test extends AbstractRectorTestCase
|
||||
{
|
||||
public function test(): void
|
||||
{
|
||||
$this->doTestFileMatchesExpectedContent(
|
||||
__DIR__ . '/Wrong/wrong.php.inc',
|
||||
__DIR__ . '/Correct/correct.php.inc'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[]
|
||||
*/
|
||||
protected function getRectorClasses(): array
|
||||
{
|
||||
return [NamespaceClassRector::class];
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
<?php declare (strict_types=1);
|
||||
|
||||
class Sniff implements PHP_CodeSniffer_Sniffs_Sniff
|
||||
{
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
<?php declare (strict_types=1);
|
||||
|
||||
$containerBuilder = new \Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
$containerBuilder->addCompilerPass(new Symfony\Bundle\FrameworkBundle\DependencyInjectino\Compiler\SerializerPass);
|
||||
$containerBuilder->addCompilerPass(new Symfony\Bundle\FrameworkBundle\DependencyInjection\Compiler\SerializerPass);
|
||||
|
|
Loading…
Reference in New Issue
Block a user