Skip to content

Commit

Permalink
respect the API in FirewallContext map
Browse files Browse the repository at this point in the history
When being merged up, this will make the SecurityBundle tests on master
green again.
  • Loading branch information
xabbuh committed Jun 24, 2017
1 parent 22723da commit ddf4368
Showing 1 changed file with 15 additions and 5 deletions.
Expand Up @@ -12,11 +12,15 @@
namespace Symfony\Bundle\SecurityBundle\Tests\Security;

use PHPUnit\Framework\TestCase;
use Symfony\Bundle\SecurityBundle\Security\FirewallConfig;
use Symfony\Bundle\SecurityBundle\Security\FirewallContext;
use Symfony\Bundle\SecurityBundle\Security\FirewallMap;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\RequestMatcherInterface;
use Symfony\Component\Security\Core\User\UserCheckerInterface;
use Symfony\Component\Security\Http\Firewall\ExceptionListener;
use Symfony\Component\Security\Http\Firewall\ListenerInterface;

class FirewallMapTest extends TestCase
{
Expand Down Expand Up @@ -58,9 +62,15 @@ public function testGetListeners()
$request = new Request();

$firewallContext = $this->getMockBuilder(FirewallContext::class)->disableOriginalConstructor()->getMock();
$firewallContext->expects($this->once())->method('getConfig')->willReturn('CONFIG');
$firewallContext->expects($this->once())->method('getListeners')->willReturn('LISTENERS');
$firewallContext->expects($this->once())->method('getExceptionListener')->willReturn('EXCEPTION LISTENER');

$firewallConfig = new FirewallConfig('main', $this->getMockBuilder(UserCheckerInterface::class)->getMock());
$firewallContext->expects($this->once())->method('getConfig')->willReturn($firewallConfig);

$listener = $this->getMockBuilder(ListenerInterface::class)->getMock();
$firewallContext->expects($this->once())->method('getListeners')->willReturn(array($listener));

$exceptionListener = $this->getMockBuilder(ExceptionListener::class)->disableOriginalConstructor()->getMock();
$firewallContext->expects($this->once())->method('getExceptionListener')->willReturn($exceptionListener);

$matcher = $this->getMockBuilder(RequestMatcherInterface::class)->getMock();
$matcher->expects($this->once())
Expand All @@ -73,8 +83,8 @@ public function testGetListeners()

$firewallMap = new FirewallMap($container, array('security.firewall.map.context.foo' => $matcher));

$this->assertEquals(array('LISTENERS', 'EXCEPTION LISTENER'), $firewallMap->getListeners($request));
$this->assertEquals('CONFIG', $firewallMap->getFirewallConfig($request));
$this->assertEquals(array(array($listener), $exceptionListener), $firewallMap->getListeners($request));
$this->assertEquals($firewallConfig, $firewallMap->getFirewallConfig($request));
$this->assertEquals('security.firewall.map.context.foo', $request->attributes->get(self::ATTRIBUTE_FIREWALL_CONTEXT));
}
}

0 comments on commit ddf4368

Please sign in to comment.