Skip to content

Commit

Permalink
minor #21680 [FrameworkBundle] resolve parameters in definition class…
Browse files Browse the repository at this point in the history
…es (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 | #21637 (comment)
| License       | MIT
| Doc PR        |

Commits
-------

37ce682 resolve parameters in definition classes
  • Loading branch information
fabpot committed Feb 20, 2017
2 parents 347f529 + 37ce682 commit f1cf0ad
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
Expand Up @@ -25,7 +25,7 @@ public function process(ContainerBuilder $container)
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');
Expand Down
Expand Up @@ -26,6 +26,9 @@ protected function setUp()
$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')
Expand All @@ -37,41 +40,69 @@ protected function setUp()
;
}

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()
{
return array(
array('Symfony\Component\Translation\Translator'),
array('%translator_implementing_bag%'),
);
}

/**
* @dataProvider getNotImplementingTranslatorBagInterfaceTranslatorClassNames
*/
public function testProcessRemovesDataCollectorTranslatorIfItDoesNotImplementTranslatorBagInterface($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('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
Expand Down

0 comments on commit f1cf0ad

Please sign in to comment.