the whole shebang
This commit is contained in:
@@ -0,0 +1,169 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;
|
||||
|
||||
use Symfony\Component\HttpKernel\HttpKernelInterface;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\ContainerAwareHttpKernel;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
|
||||
class ContainerAwareHttpKernelTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
if (!class_exists('Symfony\Component\DependencyInjection\Container')) {
|
||||
$this->markTestSkipped('The "DependencyInjection" component is not available');
|
||||
}
|
||||
|
||||
if (!class_exists('Symfony\Component\EventDispatcher\EventDispatcher')) {
|
||||
$this->markTestSkipped('The "EventDispatcher" component is not available');
|
||||
}
|
||||
|
||||
if (!class_exists('Symfony\Component\HttpFoundation\Request')) {
|
||||
$this->markTestSkipped('The "HttpFoundation" component is not available');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getProviderTypes
|
||||
*/
|
||||
public function testHandle($type)
|
||||
{
|
||||
$request = new Request();
|
||||
$expected = new Response();
|
||||
|
||||
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
|
||||
$container
|
||||
->expects($this->once())
|
||||
->method('enterScope')
|
||||
->with($this->equalTo('request'))
|
||||
;
|
||||
$container
|
||||
->expects($this->once())
|
||||
->method('leaveScope')
|
||||
->with($this->equalTo('request'))
|
||||
;
|
||||
$container
|
||||
->expects($this->at(0))
|
||||
->method('hasScope')
|
||||
->with($this->equalTo('request'))
|
||||
->will($this->returnValue(false));
|
||||
$container
|
||||
->expects($this->at(1))
|
||||
->method('addScope')
|
||||
->with($this->isInstanceOf('Symfony\Component\DependencyInjection\Scope'));
|
||||
// enterScope()
|
||||
$container
|
||||
->expects($this->at(3))
|
||||
->method('set')
|
||||
->with($this->equalTo('request'), $this->equalTo($request), $this->equalTo('request'))
|
||||
;
|
||||
$container
|
||||
->expects($this->at(4))
|
||||
->method('set')
|
||||
->with($this->equalTo('request'), $this->equalTo(null), $this->equalTo('request'))
|
||||
;
|
||||
|
||||
$dispatcher = new EventDispatcher();
|
||||
$resolver = $this->getMock('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface');
|
||||
$kernel = new ContainerAwareHttpKernel($dispatcher, $container, $resolver);
|
||||
|
||||
$controller = function() use ($expected) {
|
||||
return $expected;
|
||||
};
|
||||
|
||||
$resolver->expects($this->once())
|
||||
->method('getController')
|
||||
->with($request)
|
||||
->will($this->returnValue($controller));
|
||||
$resolver->expects($this->once())
|
||||
->method('getArguments')
|
||||
->with($request, $controller)
|
||||
->will($this->returnValue(array()));
|
||||
|
||||
$actual = $kernel->handle($request, $type);
|
||||
|
||||
$this->assertSame($expected, $actual, '->handle() returns the response');
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider getProviderTypes
|
||||
*/
|
||||
public function testHandleRestoresThePreviousRequestOnException($type)
|
||||
{
|
||||
$request = new Request();
|
||||
$expected = new \Exception();
|
||||
|
||||
$container = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface');
|
||||
$container
|
||||
->expects($this->once())
|
||||
->method('enterScope')
|
||||
->with($this->equalTo('request'))
|
||||
;
|
||||
$container
|
||||
->expects($this->once())
|
||||
->method('leaveScope')
|
||||
->with($this->equalTo('request'))
|
||||
;
|
||||
$container
|
||||
->expects($this->at(0))
|
||||
->method('hasScope')
|
||||
->with($this->equalTo('request'))
|
||||
->will($this->returnValue(true));
|
||||
// enterScope()
|
||||
$container
|
||||
->expects($this->at(2))
|
||||
->method('set')
|
||||
->with($this->equalTo('request'), $this->equalTo($request), $this->equalTo('request'))
|
||||
;
|
||||
$container
|
||||
->expects($this->at(3))
|
||||
->method('set')
|
||||
->with($this->equalTo('request'), $this->equalTo(null), $this->equalTo('request'))
|
||||
;
|
||||
|
||||
$dispatcher = new EventDispatcher();
|
||||
$resolver = $this->getMock('Symfony\\Component\\HttpKernel\\Controller\\ControllerResolverInterface');
|
||||
$kernel = new ContainerAwareHttpKernel($dispatcher, $container, $resolver);
|
||||
|
||||
$controller = function() use ($expected) {
|
||||
throw $expected;
|
||||
};
|
||||
|
||||
$resolver->expects($this->once())
|
||||
->method('getController')
|
||||
->with($request)
|
||||
->will($this->returnValue($controller));
|
||||
$resolver->expects($this->once())
|
||||
->method('getArguments')
|
||||
->with($request, $controller)
|
||||
->will($this->returnValue(array()));
|
||||
|
||||
try {
|
||||
$kernel->handle($request, $type);
|
||||
$this->fail('->handle() suppresses the controller exception');
|
||||
} catch (\PHPUnit_Framework_Exception $exception) {
|
||||
throw $exception;
|
||||
} catch (\Exception $actual) {
|
||||
$this->assertSame($expected, $actual, '->handle() throws the controller exception');
|
||||
}
|
||||
}
|
||||
|
||||
public function getProviderTypes()
|
||||
{
|
||||
return array(
|
||||
array(HttpKernelInterface::MASTER_REQUEST),
|
||||
array(HttpKernelInterface::SUB_REQUEST),
|
||||
);
|
||||
}
|
||||
}
|
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests;
|
||||
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\MergeExtensionConfigurationPass;
|
||||
|
||||
class MergeExtensionConfigurationPassTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
protected function setUp()
|
||||
{
|
||||
if (!class_exists('Symfony\Component\DependencyInjection\Container')) {
|
||||
$this->markTestSkipped('The "DependencyInjection" component is not available');
|
||||
}
|
||||
|
||||
if (!class_exists('Symfony\Component\Config\FileLocator')) {
|
||||
$this->markTestSkipped('The "Config" component is not available');
|
||||
}
|
||||
}
|
||||
|
||||
public function testAutoloadMainExtension()
|
||||
{
|
||||
$container = $this->getMock('Symfony\\Component\\DependencyInjection\\ContainerBuilder');
|
||||
$params = $this->getMock('Symfony\\Component\\DependencyInjection\\ParameterBag\\ParameterBag');
|
||||
|
||||
$container->expects($this->at(0))
|
||||
->method('getExtensionConfig')
|
||||
->with('loaded')
|
||||
->will($this->returnValue(array(array())));
|
||||
$container->expects($this->at(1))
|
||||
->method('getExtensionConfig')
|
||||
->with('notloaded')
|
||||
->will($this->returnValue(array()));
|
||||
$container->expects($this->once())
|
||||
->method('loadFromExtension')
|
||||
->with('notloaded', array());
|
||||
|
||||
$container->expects($this->any())
|
||||
->method('getParameterBag')
|
||||
->will($this->returnValue($params));
|
||||
$params->expects($this->any())
|
||||
->method('all')
|
||||
->will($this->returnValue(array()));
|
||||
$container->expects($this->any())
|
||||
->method('getDefinitions')
|
||||
->will($this->returnValue(array()));
|
||||
$container->expects($this->any())
|
||||
->method('getAliases')
|
||||
->will($this->returnValue(array()));
|
||||
$container->expects($this->any())
|
||||
->method('getExtensions')
|
||||
->will($this->returnValue(array()));
|
||||
|
||||
$configPass = new MergeExtensionConfigurationPass(array('loaded', 'notloaded'));
|
||||
$configPass->process($container);
|
||||
}
|
||||
}
|
@@ -0,0 +1,89 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\HttpKernel\Tests\DependencyInjection;
|
||||
|
||||
use Symfony\Component\DependencyInjection\ContainerBuilder;
|
||||
use Symfony\Component\DependencyInjection\Definition;
|
||||
use Symfony\Component\HttpKernel\DependencyInjection\RegisterListenersPass;
|
||||
|
||||
class RegisterListenersPassTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
/**
|
||||
* Tests that event subscribers not implementing EventSubscriberInterface
|
||||
* trigger an exception.
|
||||
*
|
||||
* @expectedException \InvalidArgumentException
|
||||
*/
|
||||
public function testEventSubscriberWithoutInterface()
|
||||
{
|
||||
// one service, not implementing any interface
|
||||
$services = array(
|
||||
'my_event_subscriber' => array(0 => array()),
|
||||
);
|
||||
|
||||
$definition = $this->getMock('Symfony\Component\DependencyInjection\Definition');
|
||||
$definition->expects($this->atLeastOnce())
|
||||
->method('getClass')
|
||||
->will($this->returnValue('stdClass'));
|
||||
|
||||
$builder = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
|
||||
$builder->expects($this->any())
|
||||
->method('hasDefinition')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
// We don't test kernel.event_listener here
|
||||
$builder->expects($this->atLeastOnce())
|
||||
->method('findTaggedServiceIds')
|
||||
->will($this->onConsecutiveCalls(array(), $services));
|
||||
|
||||
$builder->expects($this->atLeastOnce())
|
||||
->method('getDefinition')
|
||||
->will($this->returnValue($definition));
|
||||
|
||||
$registerListenersPass = new RegisterListenersPass();
|
||||
$registerListenersPass->process($builder);
|
||||
}
|
||||
|
||||
public function testValidEventSubscriber()
|
||||
{
|
||||
$services = array(
|
||||
'my_event_subscriber' => array(0 => array()),
|
||||
);
|
||||
|
||||
$definition = $this->getMock('Symfony\Component\DependencyInjection\Definition');
|
||||
$definition->expects($this->atLeastOnce())
|
||||
->method('getClass')
|
||||
->will($this->returnValue('Symfony\Component\HttpKernel\Tests\DependencyInjection\SubscriberService'));
|
||||
|
||||
$builder = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder');
|
||||
$builder->expects($this->any())
|
||||
->method('hasDefinition')
|
||||
->will($this->returnValue(true));
|
||||
|
||||
// We don't test kernel.event_listener here
|
||||
$builder->expects($this->atLeastOnce())
|
||||
->method('findTaggedServiceIds')
|
||||
->will($this->onConsecutiveCalls(array(), $services));
|
||||
|
||||
$builder->expects($this->atLeastOnce())
|
||||
->method('getDefinition')
|
||||
->will($this->returnValue($definition));
|
||||
|
||||
$registerListenersPass = new RegisterListenersPass();
|
||||
$registerListenersPass->process($builder);
|
||||
}
|
||||
}
|
||||
|
||||
class SubscriberService implements \Symfony\Component\EventDispatcher\EventSubscriberInterface
|
||||
{
|
||||
public static function getSubscribedEvents() {}
|
||||
}
|
Reference in New Issue
Block a user