Файл: symfony-2.7/src/Symfony/Component/Security/Http/Tests/FirewallTest.php
Строк: 194
<?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 SymfonyComponentSecurityHttpTests;
use SymfonyComponentSecurityHttpFirewall;
use SymfonyComponentHttpKernelEventGetResponseEvent;
use SymfonyComponentHttpKernelHttpKernelInterface;
class FirewallTest extends PHPUnit_Framework_TestCase
{
public function testOnKernelRequestRegistersExceptionListener()
{
$dispatcher = $this->getMock('SymfonyComponentEventDispatcherEventDispatcherInterface');
$listener = $this->getMock('SymfonyComponentSecurityHttpFirewallExceptionListener', array(), array(), '', false);
$listener
->expects($this->once())
->method('register')
->with($this->equalTo($dispatcher))
;
$request = $this->getMock('SymfonyComponentHttpFoundationRequest', array(), array(), '', false, false);
$map = $this->getMock('SymfonyComponentSecurityHttpFirewallMapInterface');
$map
->expects($this->once())
->method('getListeners')
->with($this->equalTo($request))
->will($this->returnValue(array(array(), $listener)))
;
$event = new GetResponseEvent($this->getMock('SymfonyComponentHttpKernelHttpKernelInterface'), $request, HttpKernelInterface::MASTER_REQUEST);
$firewall = new Firewall($map, $dispatcher);
$firewall->onKernelRequest($event);
}
public function testOnKernelRequestStopsWhenThereIsAResponse()
{
$response = $this->getMock('SymfonyComponentHttpFoundationResponse');
$first = $this->getMock('SymfonyComponentSecurityHttpFirewallListenerInterface');
$first
->expects($this->once())
->method('handle')
;
$second = $this->getMock('SymfonyComponentSecurityHttpFirewallListenerInterface');
$second
->expects($this->never())
->method('handle')
;
$map = $this->getMock('SymfonyComponentSecurityHttpFirewallMapInterface');
$map
->expects($this->once())
->method('getListeners')
->will($this->returnValue(array(array($first, $second), null)))
;
$event = $this->getMock(
'SymfonyComponentHttpKernelEventGetResponseEvent',
array('hasResponse'),
array(
$this->getMock('SymfonyComponentHttpKernelHttpKernelInterface'),
$this->getMock('SymfonyComponentHttpFoundationRequest', array(), array(), '', false, false),
HttpKernelInterface::MASTER_REQUEST,
)
);
$event
->expects($this->once())
->method('hasResponse')
->will($this->returnValue(true))
;
$firewall = new Firewall($map, $this->getMock('SymfonyComponentEventDispatcherEventDispatcherInterface'));
$firewall->onKernelRequest($event);
}
public function testOnKernelRequestWithSubRequest()
{
$map = $this->getMock('SymfonyComponentSecurityHttpFirewallMapInterface');
$map
->expects($this->never())
->method('getListeners')
;
$event = new GetResponseEvent(
$this->getMock('SymfonyComponentHttpKernelHttpKernelInterface'),
$this->getMock('SymfonyComponentHttpFoundationRequest'),
HttpKernelInterface::SUB_REQUEST
);
$firewall = new Firewall($map, $this->getMock('SymfonyComponentEventDispatcherEventDispatcherInterface'));
$firewall->onKernelRequest($event);
$this->assertFalse($event->hasResponse());
}
}