mirror of
https://github.com/rectorphp/rector.git
synced 2025-01-19 06:18:07 +01:00
Merge pull request #562 from rectorphp/container-get-to-construcotr-rector-alias
[FrameworkBundle] Add test for services alias as well
This commit is contained in:
commit
337d069df7
@ -35,7 +35,7 @@ final class ContainerGetToConstructorInjectionRector extends AbstractToConstruct
|
||||
[
|
||||
new CodeSample(
|
||||
<<<'CODE_SAMPLE'
|
||||
class MyCommand extends ContainerAwareCommand
|
||||
final class SomeCommand extends ContainerAwareCommand
|
||||
{
|
||||
public function someMethod()
|
||||
{
|
||||
@ -47,7 +47,7 @@ class MyCommand extends ContainerAwareCommand
|
||||
CODE_SAMPLE
|
||||
,
|
||||
<<<'CODE_SAMPLE'
|
||||
class MyCommand extends Command
|
||||
final class SomeCommand extends Command
|
||||
{
|
||||
public function __construct(SomeService $someService)
|
||||
{
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace Rector\Symfony\Tests\FrameworkBundle\AbstractToConstructorInjectionRectorSource;
|
||||
|
||||
use Rector\Symfony\Tests\Rector\FrameworkBundle\AbstractToConstructorInjectionRectorSource\SomeTranslator;
|
||||
use Rector\Symfony\Tests\Rector\FrameworkBundle\AbstractToConstructorInjectionRectorSource\SomeTranslatorInterface;
|
||||
use Symfony\Component\Config\Loader\LoaderInterface;
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
@ -21,6 +23,11 @@ final class SomeKernelClass extends Kernel
|
||||
protected function build(ContainerBuilder $containerBuilder): void
|
||||
{
|
||||
$containerBuilder->register('some_service', 'stdClass');
|
||||
|
||||
$containerBuilder->register('translator.data_collector', SomeTranslator::class);
|
||||
|
||||
$containerBuilder->setAlias('translator', 'translator.data_collector');
|
||||
$containerBuilder->setAlias(SomeTranslatorInterface::class, 'translator.data_collector');
|
||||
}
|
||||
|
||||
public function getCacheDir()
|
||||
|
@ -0,0 +1,8 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Symfony\Tests\Rector\FrameworkBundle\AbstractToConstructorInjectionRectorSource;
|
||||
|
||||
final class SomeTranslator
|
||||
{
|
||||
|
||||
}
|
@ -0,0 +1,8 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
namespace Rector\Symfony\Tests\Rector\FrameworkBundle\AbstractToConstructorInjectionRectorSource;
|
||||
|
||||
interface SomeTranslatorInterface
|
||||
{
|
||||
|
||||
}
|
@ -21,6 +21,7 @@ final class ContainerGetToConstructorInjectionRectorTest extends AbstractRectorT
|
||||
public function provideWrongToFixedFiles(): Iterator
|
||||
{
|
||||
yield [__DIR__ . '/Wrong/wrong.php.inc', __DIR__ . '/Correct/correct.php.inc'];
|
||||
yield [__DIR__ . '/Wrong/wrong2.php.inc', __DIR__ . '/Correct/correct2.php.inc'];
|
||||
}
|
||||
|
||||
protected function provideConfig(): string
|
||||
|
@ -0,0 +1,21 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use Rector\Symfony\Tests\FrameworkBundle\ContainerGetToConstructorInjectionRector\Source\ContainerAwareParentClass;
|
||||
|
||||
final class AnotherCommand extends ContainerAwareParentClass
|
||||
{
|
||||
/**
|
||||
* @var \Rector\Symfony\Tests\Rector\FrameworkBundle\AbstractToConstructorInjectionRectorSource\SomeTranslator
|
||||
*/
|
||||
private $someTranslator;
|
||||
public function __construct(\Rector\Symfony\Tests\Rector\FrameworkBundle\AbstractToConstructorInjectionRectorSource\SomeTranslator $someTranslator)
|
||||
{
|
||||
$this->someTranslator = $someTranslator;
|
||||
}
|
||||
protected function execute()
|
||||
{
|
||||
$someService = $this->someTranslator;
|
||||
|
||||
$someService = $this->someTranslator->translateSomething();
|
||||
}
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
<?php declare(strict_types=1);
|
||||
|
||||
use Rector\Symfony\Tests\FrameworkBundle\ContainerGetToConstructorInjectionRector\Source\ContainerAwareParentClass;
|
||||
|
||||
final class AnotherCommand extends ContainerAwareParentClass
|
||||
{
|
||||
protected function execute()
|
||||
{
|
||||
$someService = $this->getContainer()->get('translator');
|
||||
|
||||
$someService = $this->getContainer()->get('translator')->translateSomething();
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user