Skip to content

Commit

Permalink
minor #23287 respect the API in FirewallContext map (xabbuh)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.3 branch.

Discussion
----------

respect the API in FirewallContext map

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets |
| License       | MIT
| Doc PR        |

When being merged up, this will make the SecurityBundle tests on master
green again.

Commits
-------

ddf4368 respect the API in FirewallContext map
  • Loading branch information
fabpot committed Jun 24, 2017
2 parents 22723da + ddf4368 commit 87601ba
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 87601ba

Please sign in to comment.