FirewallSubscriberTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 1
Bugs 1 Features 0
Metric Value
wmc 3
lcom 1
cbo 8
dl 0
loc 44
rs 10
c 1
b 1
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 15 1
A testGetSubscribedEvents() 0 7 1
A testOnPresenter() 0 12 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Symplify\SymfonySecurity\Tests\EventSubscriber;
6
7
use Nette\Application\Application;
8
use Nette\Application\ForbiddenRequestException;
9
use Nette\Application\IPresenter;
10
use Nette\Application\Request as ApplicationRequest;
11
use Nette\Http\Request;
12
use Nette\Http\UrlScript;
13
use PHPUnit\Framework\TestCase;
14
use Prophecy\Argument;
15
use Symplify\SymfonyEventDispatcher\Adapter\Nette\Event\PresenterCreatedEvent;
16
use Symplify\SymfonySecurity\Contract\Http\FirewallHandlerInterface;
17
use Symplify\SymfonySecurity\Contract\Http\FirewallMapInterface;
18
use Symplify\SymfonySecurity\EventSubscriber\FirewallSubscriber;
19
20
final class FirewallSubscriberTest extends TestCase
21
{
22
    /**
23
     * @var FirewallSubscriber
24
     */
25
    private $firewall;
26
27
    protected function setUp()
28
    {
29
        $listenerMock = $this->prophesize(FirewallHandlerInterface::class);
30
        $listenerMock->handle(Argument::cetera())->willReturn(function () {
31
            throw new ForbiddenRequestException();
32
        });
33
34
        $firewallMapMock = $this->prophesize(FirewallMapInterface::class);
35
        $firewallMapMock->getListeners(Argument::type(Request::class))->willReturn(
36
            [[$listenerMock->reveal()], '']
37
        );
38
39
        $request = new Request((new UrlScript())->setScriptPath('admin/script.php'));
40
        $this->firewall = new FirewallSubscriber($firewallMapMock->reveal(), $request);
41
    }
42
43
    public function testGetSubscribedEvents()
44
    {
45
        $this->assertSame(
46
            [PresenterCreatedEvent::NAME => 'onPresenter'],
47
            $this->firewall->getSubscribedEvents()
48
        );
49
    }
50
51
    public function testOnPresenter()
52
    {
53
        $requestMock = $this->prophesize(ApplicationRequest::class);
54
        $requestMock->getParameters()->willReturn(['parameter' => 'value']);
55
56
        $applicationPresenterEventMock = new PresenterCreatedEvent(
57
            $this->prophesize(Application::class)->reveal(),
58
            $this->prophesize(IPresenter::class)->reveal()
59
        );
60
61
        $this->firewall->onPresenter($applicationPresenterEventMock);
62
    }
63
}
64