[HttpKernel] fixed missing use cases
This commit is contained in:
parent
bd01a29eb4
commit
969c5d92b3
@ -60,13 +60,13 @@ class FragmentRendererPass implements CompilerPassInterface
|
|||||||
|
|
||||||
foreach ($tags as $tag) {
|
foreach ($tags as $tag) {
|
||||||
if (!isset($tag['alias'])) {
|
if (!isset($tag['alias'])) {
|
||||||
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);
|
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);
|
||||||
|
|
||||||
// register the handler as a non-lazy-loaded one
|
// register the handler as a non-lazy-loaded one
|
||||||
$definition->addMethodCall('addRenderer', array(new Reference($id)));
|
$definition->addMethodCall('addRenderer', array(new Reference($id)));
|
||||||
|
} else {
|
||||||
|
$definition->addMethodCall('addRendererService', array($tag['alias'], $id));
|
||||||
}
|
}
|
||||||
|
|
||||||
$definition->addMethodCall('addRendererService', array($tag['alias'], $id));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,12 +11,60 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;
|
namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;
|
||||||
|
|
||||||
|
use Symfony\Component\DependencyInjection\Reference;
|
||||||
use Symfony\Component\HttpFoundation\Request;
|
use Symfony\Component\HttpFoundation\Request;
|
||||||
use Symfony\Component\HttpKernel\DependencyInjection\FragmentRendererPass;
|
use Symfony\Component\HttpKernel\DependencyInjection\FragmentRendererPass;
|
||||||
use Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface;
|
use Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface;
|
||||||
|
|
||||||
class FragmentRendererPassTest extends \PHPUnit_Framework_TestCase
|
class FragmentRendererPassTest extends \PHPUnit_Framework_TestCase
|
||||||
{
|
{
|
||||||
|
public function testLegacyFragmentRedererWithoutAlias()
|
||||||
|
{
|
||||||
|
$this->iniSet('error_reporting', -1 & ~E_USER_DEPRECATED);
|
||||||
|
|
||||||
|
// no alias
|
||||||
|
$services = array(
|
||||||
|
'my_content_renderer' => array(array()),
|
||||||
|
);
|
||||||
|
|
||||||
|
$renderer = $this->getMock('Symfony\Component\DependencyInjection\Definition');
|
||||||
|
$renderer
|
||||||
|
->expects($this->once())
|
||||||
|
->method('addMethodCall')
|
||||||
|
->with('addRenderer', array(new Reference('my_content_renderer')))
|
||||||
|
;
|
||||||
|
|
||||||
|
$definition = $this->getMock('Symfony\Component\DependencyInjection\Definition');
|
||||||
|
$definition->expects($this->atLeastOnce())
|
||||||
|
->method('getClass')
|
||||||
|
->will($this->returnValue('Symfony\Component\HttpKernel\Tests\DependencyInjection\RendererService'));
|
||||||
|
$definition
|
||||||
|
->expects($this->once())
|
||||||
|
->method('isPublic')
|
||||||
|
->will($this->returnValue(true))
|
||||||
|
;
|
||||||
|
|
||||||
|
$builder = $this->getMock(
|
||||||
|
'Symfony\Component\DependencyInjection\ContainerBuilder',
|
||||||
|
array('hasDefinition', 'findTaggedServiceIds', 'getDefinition')
|
||||||
|
);
|
||||||
|
$builder->expects($this->any())
|
||||||
|
->method('hasDefinition')
|
||||||
|
->will($this->returnValue(true));
|
||||||
|
|
||||||
|
// We don't test kernel.fragment_renderer here
|
||||||
|
$builder->expects($this->atLeastOnce())
|
||||||
|
->method('findTaggedServiceIds')
|
||||||
|
->will($this->returnValue($services));
|
||||||
|
|
||||||
|
$builder->expects($this->atLeastOnce())
|
||||||
|
->method('getDefinition')
|
||||||
|
->will($this->onConsecutiveCalls($renderer, $definition));
|
||||||
|
|
||||||
|
$pass = new FragmentRendererPass();
|
||||||
|
$pass->process($builder);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests that content rendering not implementing FragmentRendererInterface
|
* Tests that content rendering not implementing FragmentRendererInterface
|
||||||
* trigger an exception.
|
* trigger an exception.
|
||||||
@ -27,7 +75,7 @@ class FragmentRendererPassTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
// one service, not implementing any interface
|
// one service, not implementing any interface
|
||||||
$services = array(
|
$services = array(
|
||||||
'my_content_renderer' => array('alias' => 'foo'),
|
'my_content_renderer' => array(array('alias' => 'foo')),
|
||||||
);
|
);
|
||||||
|
|
||||||
$definition = $this->getMock('Symfony\Component\DependencyInjection\Definition');
|
$definition = $this->getMock('Symfony\Component\DependencyInjection\Definition');
|
||||||
|
Reference in New Issue
Block a user