Skip to content

Commit

Permalink
[HttpKernel] fixed missing use cases
Browse files Browse the repository at this point in the history
  • Loading branch information
fabpot committed Jan 13, 2015
1 parent bd01a29 commit 969c5d9
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ public function process(ContainerBuilder $container)

foreach ($tags as $tag) {
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
$definition->addMethodCall('addRenderer', array(new Reference($id)));
} else {
$definition->addMethodCall('addRendererService', array($tag['alias'], $id));
}

$definition->addMethodCall('addRendererService', array($tag['alias'], $id));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,60 @@

namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;

use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpKernel\DependencyInjection\FragmentRendererPass;
use Symfony\Component\HttpKernel\Fragment\FragmentRendererInterface;

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
* trigger an exception.
Expand All @@ -27,7 +75,7 @@ public function testContentRendererWithoutInterface()
{
// one service, not implementing any interface
$services = array(
'my_content_renderer' => array('alias' => 'foo'),
'my_content_renderer' => array(array('alias' => 'foo')),
);

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

0 comments on commit 969c5d9

Please sign in to comment.