|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is part of the Symfony package. |
| 5 | + * |
| 6 | + * (c) Fabien Potencier <[email protected]> |
| 7 | + * |
| 8 | + * For the full copyright and license information, please view the LICENSE |
| 9 | + * file that was distributed with this source code. |
| 10 | + */ |
| 11 | + |
| 12 | +namespace Symfony\Bundle\SecurityBundle\Tests\Security; |
| 13 | + |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | +use Symfony\Bundle\SecurityBundle\Security\FirewallContext; |
| 16 | +use Symfony\Bundle\SecurityBundle\Security\FirewallMap; |
| 17 | +use Symfony\Component\DependencyInjection\Container; |
| 18 | +use Symfony\Component\HttpFoundation\Request; |
| 19 | +use Symfony\Component\HttpFoundation\RequestMatcherInterface; |
| 20 | + |
| 21 | +class FirewallMapTest extends TestCase |
| 22 | +{ |
| 23 | + public function testGetListenersWithEmptyMap() |
| 24 | + { |
| 25 | + $request = new Request(); |
| 26 | + |
| 27 | + $map = array(); |
| 28 | + $container = $this->getMockBuilder(Container::class)->getMock(); |
| 29 | + $container->expects($this->never())->method('get'); |
| 30 | + |
| 31 | + $firewallMap = new FirewallMap($container, $map); |
| 32 | + |
| 33 | + $this->assertEquals(array(array(), null), $firewallMap->getListeners($request)); |
| 34 | + |
| 35 | + $this->assertNull($firewallMap->getFirewallConfig($request)); |
| 36 | + } |
| 37 | + |
| 38 | + public function testGetListeners() |
| 39 | + { |
| 40 | + $request = new Request(); |
| 41 | + |
| 42 | + $firewallContext = $this->getMockBuilder(FirewallContext::class)->disableOriginalConstructor()->getMock(); |
| 43 | + $firewallContext->expects($this->once())->method('getConfig')->willReturn('CONFIG'); |
| 44 | + $firewallContext->expects($this->once())->method('getListeners')->willReturn('LISTENERS'); |
| 45 | + $firewallContext->expects($this->once())->method('getExceptionListener')->willReturn('EXCEPTION LISTENER'); |
| 46 | + |
| 47 | + $matcher = $this->getMockBuilder(RequestMatcherInterface::class)->getMock(); |
| 48 | + $matcher->expects($this->once()) |
| 49 | + ->method('matches') |
| 50 | + ->with($request) |
| 51 | + ->willReturn(true); |
| 52 | + |
| 53 | + $container = $this->getMockBuilder(Container::class)->getMock(); |
| 54 | + $container->expects($this->exactly(2))->method('get')->willReturn($firewallContext); |
| 55 | + |
| 56 | + $firewallMap = new FirewallMap($container, array('security.firewall.map.context.foo' => $matcher)); |
| 57 | + |
| 58 | + $this->assertEquals(array('LISTENERS', 'EXCEPTION LISTENER'), $firewallMap->getListeners($request)); |
| 59 | + $this->assertEquals('CONFIG', $firewallMap->getFirewallConfig($request)); |
| 60 | + } |
| 61 | +} |
0 commit comments