Skip to content

Commit fa5d5de

Browse files
Merge branch '2.7' into 2.8
* 2.7: Further refactorings to PHPUnit namespaces resolve parameters in definition classes
2 parents c577520 + 749d918 commit fa5d5de

File tree

6 files changed

+50
-14
lines changed

6 files changed

+50
-14
lines changed

DependencyInjection/Compiler/DataCollectorTranslatorPass.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public function process(ContainerBuilder $container)
2525
return;
2626
}
2727

28-
$translatorClass = $container->findDefinition('translator')->getClass();
28+
$translatorClass = $container->getParameterBag()->resolveValue($container->findDefinition('translator')->getClass());
2929

3030
if (!is_subclass_of($translatorClass, 'Symfony\Component\Translation\TranslatorBagInterface')) {
3131
$container->removeDefinition('translator.data_collector');

Tests/Controller/ControllerResolverTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,12 @@ public function testGetControllerInvokableServiceWithClassNameAsName()
141141
*/
142142
public function testGetControllerOnNonUndefinedFunction($controller, $exceptionName = null, $exceptionMessage = null)
143143
{
144-
$this->setExpectedException($exceptionName, $exceptionMessage);
144+
if (method_exists($this, 'expectException')) {
145+
$this->expectException($exceptionName);
146+
$this->expectExceptionMessage($exceptionMessage);
147+
} else {
148+
$this->setExpectedException($exceptionName, $exceptionMessage);
149+
}
145150

146151
parent::testGetControllerOnNonUndefinedFunction($controller);
147152
}

Tests/DependencyInjection/Compiler/DataCollectorTranslatorPassTest.php

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ protected function setUp()
2727
$this->container = new ContainerBuilder();
2828
$this->dataCollectorTranslatorPass = new DataCollectorTranslatorPass();
2929

30+
$this->container->setParameter('translator_implementing_bag', 'Symfony\Component\Translation\Translator');
31+
$this->container->setParameter('translator_not_implementing_bag', 'Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\TranslatorWithTranslatorBag');
32+
3033
$this->container->register('translator.data_collector', 'Symfony\Component\Translation\DataCollectorTranslator')
3134
->setPublic(false)
3235
->setDecoratedService('translator')
@@ -38,41 +41,69 @@ protected function setUp()
3841
;
3942
}
4043

41-
public function testProcessKeepsDataCollectorTranslatorIfItImplementsTranslatorBagInterface()
44+
/**
45+
* @dataProvider getImplementingTranslatorBagInterfaceTranslatorClassNames
46+
*/
47+
public function testProcessKeepsDataCollectorTranslatorIfItImplementsTranslatorBagInterface($class)
4248
{
43-
$this->container->register('translator', 'Symfony\Component\Translation\Translator');
49+
$this->container->register('translator', $class);
4450

4551
$this->dataCollectorTranslatorPass->process($this->container);
4652

4753
$this->assertTrue($this->container->hasDefinition('translator.data_collector'));
4854
}
4955

50-
public function testProcessKeepsDataCollectorIfTranslatorImplementsTranslatorBagInterface()
56+
/**
57+
* @dataProvider getImplementingTranslatorBagInterfaceTranslatorClassNames
58+
*/
59+
public function testProcessKeepsDataCollectorIfTranslatorImplementsTranslatorBagInterface($class)
5160
{
52-
$this->container->register('translator', 'Symfony\Component\Translation\Translator');
61+
$this->container->register('translator', $class);
5362

5463
$this->dataCollectorTranslatorPass->process($this->container);
5564

5665
$this->assertTrue($this->container->hasDefinition('data_collector.translation'));
5766
}
5867

59-
public function testProcessRemovesDataCollectorTranslatorIfItDoesNotImplementTranslatorBagInterface()
68+
public function getImplementingTranslatorBagInterfaceTranslatorClassNames()
69+
{
70+
return array(
71+
array('Symfony\Component\Translation\Translator'),
72+
array('%translator_implementing_bag%'),
73+
);
74+
}
75+
76+
/**
77+
* @dataProvider getNotImplementingTranslatorBagInterfaceTranslatorClassNames
78+
*/
79+
public function testProcessRemovesDataCollectorTranslatorIfItDoesNotImplementTranslatorBagInterface($class)
6080
{
61-
$this->container->register('translator', 'Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\TranslatorWithTranslatorBag');
81+
$this->container->register('translator', $class);
6282

6383
$this->dataCollectorTranslatorPass->process($this->container);
6484

6585
$this->assertFalse($this->container->hasDefinition('translator.data_collector'));
6686
}
6787

68-
public function testProcessRemovesDataCollectorIfTranslatorDoesNotImplementTranslatorBagInterface()
88+
/**
89+
* @dataProvider getNotImplementingTranslatorBagInterfaceTranslatorClassNames
90+
*/
91+
public function testProcessRemovesDataCollectorIfTranslatorDoesNotImplementTranslatorBagInterface($class)
6992
{
70-
$this->container->register('translator', 'Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\TranslatorWithTranslatorBag');
93+
$this->container->register('translator', $class);
7194

7295
$this->dataCollectorTranslatorPass->process($this->container);
7396

7497
$this->assertFalse($this->container->hasDefinition('data_collector.translation'));
7598
}
99+
100+
public function getNotImplementingTranslatorBagInterfaceTranslatorClassNames()
101+
{
102+
return array(
103+
array('Symfony\Bundle\FrameworkBundle\Tests\DependencyInjection\Compiler\TranslatorWithTranslatorBag'),
104+
array('%translator_not_implementing_bag%'),
105+
);
106+
}
76107
}
77108

78109
class TranslatorWithTranslatorBag implements TranslatorInterface

Tests/DependencyInjection/Compiler/ProfilerPassTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function testTemplateNoIdThrowsException()
4141

4242
$builder = $this->createContainerMock($services);
4343

44-
$this->setExpectedException('InvalidArgumentException');
44+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('InvalidArgumentException');
4545

4646
$profilerPass = new ProfilerPass();
4747
$profilerPass->process($builder);

Tests/DependencyInjection/Compiler/SerializerPassTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testThrowExceptionWhenNoNormalizers()
3636
->with('serializer.normalizer')
3737
->will($this->returnValue(array()));
3838

39-
$this->setExpectedException('RuntimeException');
39+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('RuntimeException');
4040

4141
$serializerPass = new SerializerPass();
4242
$serializerPass->process($container);
@@ -63,7 +63,7 @@ public function testThrowExceptionWhenNoEncoders()
6363
->method('getDefinition')
6464
->will($this->returnValue($definition));
6565

66-
$this->setExpectedException('RuntimeException');
66+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('RuntimeException');
6767

6868
$serializerPass = new SerializerPass();
6969
$serializerPass->process($container);

Tests/Translation/TranslatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public function testTransWithCachingWithInvalidLocale()
101101
$translator = $this->getTranslator($loader, array('cache_dir' => $this->tmpDir), 'loader', '\Symfony\Bundle\FrameworkBundle\Tests\Translation\TranslatorWithInvalidLocale');
102102
$translator->setLocale('invalid locale');
103103

104-
$this->setExpectedException('\InvalidArgumentException');
104+
$this->{method_exists($this, $_ = 'expectException') ? $_ : 'setExpectedException'}('\InvalidArgumentException');
105105
$translator->trans('foo');
106106
}
107107

0 commit comments

Comments
 (0)