Skip to content

Commit e7d98f7

Browse files
committed
[HttpKernel] fixed missing use cases
1 parent bb9fe65 commit e7d98f7

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

DependencyInjection/FragmentRendererPass.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ public function process(ContainerBuilder $container)
6060

6161
foreach ($tags as $tag) {
6262
if (!isset($tag['alias'])) {
63-
trigger_error(sprintf('Service "%s" will have to define the "alias" attribute on the "%s" tag as of Symfony 3.0.', $id, $this->fragmentTag), E_USER_DEPRECATED);
63+
trigger_error(sprintf('Service "%s" will have to define the "alias" attribute on the "%s" tag as of Symfony 3.0.', $id, $this->rendererTag), E_USER_DEPRECATED);
6464

6565
// register the handler as a non-lazy-loaded one
6666
$definition->addMethodCall('addRenderer', array(new Reference($id)));
67+
} else {
68+
$definition->addMethodCall('addRendererService', array($tag['alias'], $id));
6769
}
68-
69-
$definition->addMethodCall('addRendererService', array($tag['alias'], $id));
7070
}
7171
}
7272
}

Tests/DependencyInjection/FragmentRendererPassTest.php

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,60 @@
1111

1212
namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;
1313

14+
use Symfony\Component\DependencyInjection\Reference;
1415
use Symfony\Component\HttpFoundation\Request;
1516
use Symfony\Component\HttpKernel\DependencyInjection\FragmentRendererPass;
1617
use Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface;
1718

1819
class FragmentRendererPassTest extends \PHPUnit_Framework_TestCase
1920
{
21+
public function testLegacyFragmentRedererWithoutAlias()
22+
{
23+
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
24+
25+
// no alias
26+
$services = array(
27+
'my_content_renderer' => array(array()),
28+
);
29+
30+
$renderer = $this->getMock('Symfony\Component\DependencyInjection\Definition');
31+
$renderer
32+
->expects($this->once())
33+
->method('addMethodCall')
34+
->with('addRenderer', array(new Reference('my_content_renderer')))
35+
;
36+
37+
$definition = $this->getMock('Symfony\Component\DependencyInjection\Definition');
38+
$definition->expects($this->atLeastOnce())
39+
->method('getClass')
40+
->will($this->returnValue('Symfony\Component\HttpKernel\Tests\DependencyInjection\RendererService'));
41+
$definition
42+
->expects($this->once())
43+
->method('isPublic')
44+
->will($this->returnValue(true))
45+
;
46+
47+
$builder = $this->getMock(
48+
'Symfony\Component\DependencyInjection\ContainerBuilder',
49+
array('hasDefinition', 'findTaggedServiceIds', 'getDefinition')
50+
);
51+
$builder->expects($this->any())
52+
->method('hasDefinition')
53+
->will($this->returnValue(true));
54+
55+
// We don't test kernel.fragment_renderer here
56+
$builder->expects($this->atLeastOnce())
57+
->method('findTaggedServiceIds')
58+
->will($this->returnValue($services));
59+
60+
$builder->expects($this->atLeastOnce())
61+
->method('getDefinition')
62+
->will($this->onConsecutiveCalls($renderer, $definition));
63+
64+
$pass = new FragmentRendererPass();
65+
$pass->process($builder);
66+
}
67+
2068
/**
2169
* Tests that content rendering not implementing FragmentRendererInterface
2270
* trigger an exception.
@@ -27,7 +75,7 @@ public function testContentRendererWithoutInterface()
2775
{
2876
// one service, not implementing any interface
2977
$services = array(
30-
'my_content_renderer' => array('alias' => 'foo'),
78+
'my_content_renderer' => array(array('alias' => 'foo')),
3179
);
3280

3381
$definition = $this->getMock('Symfony\Component\DependencyInjection\Definition');

0 commit comments

Comments
 (0)