Skip to content

Commit 66fcb05

Browse files
Merge branch '3.2'
* 3.2: Refactored other PHPUnit method calls to work with namespaced PHPUnit 6 Refactored other PHPUnit method calls to work with namespaced PHPUnit 6 Further refactorings to PHPUnit namespaces resolve parameters in definition classes
2 parents acd58af + de5b06b commit 66fcb05

File tree

7 files changed

+65
-14
lines changed

7 files changed

+65
-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
@@ -143,7 +143,12 @@ public function testGetControllerOnNonUndefinedFunction($controller, $exceptionN
143143
{
144144
// All this logic needs to be duplicated, since calling parent::testGetControllerOnNonUndefinedFunction will override the expected excetion and not use the regex
145145
$resolver = $this->createControllerResolver();
146-
$this->setExpectedExceptionRegExp($exceptionName, $exceptionMessage);
146+
if (method_exists($this, 'expectException')) {
147+
$this->expectException($exceptionName);
148+
$this->expectExceptionMessageRegExp($exceptionMessage);
149+
} else {
150+
$this->setExpectedExceptionRegExp($exceptionName, $exceptionMessage);
151+
}
147152

148153
$request = Request::create('/');
149154
$request->attributes->set('_controller', $controller);

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/FormPassTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,12 @@ public function testPrivateTaggedServices($id, $tagName, $expectedExceptionMessa
197197
$container->setDefinition('form.extension', $extDefinition);
198198
$container->register($id, 'stdClass')->setPublic(false)->addTag($tagName);
199199

200-
$this->setExpectedException('\InvalidArgumentException', $expectedExceptionMessage);
200+
if (method_exists($this, 'expectException')) {
201+
$this->expectException('InvalidArgumentException');
202+
$this->expectExceptionMessage($expectedExceptionMessage);
203+
} else {
204+
$this->setExpectedException('InvalidArgumentException', $expectedExceptionMessage);
205+
}
201206

202207
$container->compile();
203208
}

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
@@ -38,7 +38,7 @@ public function testThrowExceptionWhenNoNormalizers()
3838
->with('serializer.normalizer')
3939
->will($this->returnValue(array()));
4040

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

4343
$serializerPass = new SerializerPass();
4444
$serializerPass->process($container);
@@ -65,7 +65,7 @@ public function testThrowExceptionWhenNoEncoders()
6565
->method('getDefinition')
6666
->will($this->returnValue($definition));
6767

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

7070
$serializerPass = new SerializerPass();
7171
$serializerPass->process($container);

Tests/Functional/CachePoolsTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ public function testRedisCachePools()
3939
{
4040
try {
4141
$this->doTestCachePools(array('root_config' => 'redis_config.yml', 'environment' => 'redis_cache'), RedisAdapter::class);
42+
} catch (\PHPUnit\Framework\Error\Warning $e) {
43+
if (0 !== strpos($e->getMessage(), 'unable to connect to')) {
44+
throw $e;
45+
}
46+
$this->markTestSkipped($e->getMessage());
4247
} catch (\PHPUnit_Framework_Error_Warning $e) {
4348
if (0 !== strpos($e->getMessage(), 'unable to connect to')) {
4449
throw $e;
@@ -59,6 +64,11 @@ public function testRedisCustomCachePools()
5964
{
6065
try {
6166
$this->doTestCachePools(array('root_config' => 'redis_custom_config.yml', 'environment' => 'custom_redis_cache'), RedisAdapter::class);
67+
} catch (\PHPUnit\Framework\Error\Warning $e) {
68+
if (0 !== strpos($e->getMessage(), 'unable to connect to')) {
69+
throw $e;
70+
}
71+
$this->markTestSkipped($e->getMessage());
6272
} catch (\PHPUnit_Framework_Error_Warning $e) {
6373
if (0 !== strpos($e->getMessage(), 'unable to connect to')) {
6474
throw $e;

0 commit comments

Comments
 (0)