minor #21680 [FrameworkBundle] resolve parameters in definition classes (xabbuh)

This PR was merged into the 2.7 branch.

Discussion
----------

[FrameworkBundle] resolve parameters in definition classes

| Q             | A
| ------------- | ---
| Branch?       | 2.7
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | https://github.com/symfony/symfony/pull/21637#discussion_r101814478
| License       | MIT
| Doc PR        |

Commits
-------

37ce682947 resolve parameters in definition classes
This commit is contained in:
Fabien Potencier 2017-02-20 08:59:53 -08:00
commit f1cf0ad334
2 changed files with 40 additions and 9 deletions

View File

@ -25,7 +25,7 @@ class DataCollectorTranslatorPass implements CompilerPassInterface
return;
}
$translatorClass = $container->findDefinition('translator')->getClass();
$translatorClass = $container->getParameterBag()->resolveValue($container->findDefinition('translator')->getClass());
if (!is_subclass_of($translatorClass, 'Symfony\Component\Translation\TranslatorBagInterface')) {
$container->removeDefinition('translator.data_collector');

View File

@ -26,6 +26,9 @@ class DataCollectorTranslatorPassTest extends \PHPUnit_Framework_TestCase
$this->container = new ContainerBuilder();
$this->dataCollectorTranslatorPass = new DataCollectorTranslatorPass();
$this->container->setParameter('translator_implementing_bag', 'Symfony\Component\Translation\Translator');
$this->container->setParameter('translator_not_implementing_bag', 'Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\TranslatorWithTranslatorBag');
$this->container->register('translator.data_collector', 'Symfony\Component\Translation\DataCollectorTranslator')
->setPublic(false)
->setDecoratedService('translator')
@ -37,41 +40,69 @@ class DataCollectorTranslatorPassTest extends \PHPUnit_Framework_TestCase
;
}
public function testProcessKeepsDataCollectorTranslatorIfItImplementsTranslatorBagInterface()
/**
* @dataProvider getImplementingTranslatorBagInterfaceTranslatorClassNames
*/
public function testProcessKeepsDataCollectorTranslatorIfItImplementsTranslatorBagInterface($class)
{
$this->container->register('translator', 'Symfony\Component\Translation\Translator');
$this->container->register('translator', $class);
$this->dataCollectorTranslatorPass->process($this->container);
$this->assertTrue($this->container->hasDefinition('translator.data_collector'));
}
public function testProcessKeepsDataCollectorIfTranslatorImplementsTranslatorBagInterface()
/**
* @dataProvider getImplementingTranslatorBagInterfaceTranslatorClassNames
*/
public function testProcessKeepsDataCollectorIfTranslatorImplementsTranslatorBagInterface($class)
{
$this->container->register('translator', 'Symfony\Component\Translation\Translator');
$this->container->register('translator', $class);
$this->dataCollectorTranslatorPass->process($this->container);
$this->assertTrue($this->container->hasDefinition('data_collector.translation'));
}
public function testProcessRemovesDataCollectorTranslatorIfItDoesNotImplementTranslatorBagInterface()
public function getImplementingTranslatorBagInterfaceTranslatorClassNames()
{
$this->container->register('translator', 'Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\TranslatorWithTranslatorBag');
return array(
array('Symfony\Component\Translation\Translator'),
array('%translator_implementing_bag%'),
);
}
/**
* @dataProvider getNotImplementingTranslatorBagInterfaceTranslatorClassNames
*/
public function testProcessRemovesDataCollectorTranslatorIfItDoesNotImplementTranslatorBagInterface($class)
{
$this->container->register('translator', $class);
$this->dataCollectorTranslatorPass->process($this->container);
$this->assertFalse($this->container->hasDefinition('translator.data_collector'));
}
public function testProcessRemovesDataCollectorIfTranslatorDoesNotImplementTranslatorBagInterface()
/**
* @dataProvider getNotImplementingTranslatorBagInterfaceTranslatorClassNames
*/
public function testProcessRemovesDataCollectorIfTranslatorDoesNotImplementTranslatorBagInterface($class)
{
$this->container->register('translator', 'Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\TranslatorWithTranslatorBag');
$this->container->register('translator', $class);
$this->dataCollectorTranslatorPass->process($this->container);
$this->assertFalse($this->container->hasDefinition('data_collector.translation'));
}
public function getNotImplementingTranslatorBagInterfaceTranslatorClassNames()
{
return array(
array('Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\TranslatorWithTranslatorBag'),
array('%translator_not_implementing_bag%'),
);
}
}
class TranslatorWithTranslatorBag implements TranslatorInterface