Completed
Pull Request — master (#1)
by Rafał
02:38
created

TenantableListenerSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 37
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 6 1
A it_is_initializable() 0 4 1
A it_implements_event_subscriber_interface() 0 4 1
A it_subscribes_to_event() 0 6 1
A it_skips_tenantable_filter_on_kernel_request() 0 10 1
1
<?php
2
3
/**
4
 * This file is part of the Superdesk Web Publisher MultiTenancy Bundle.
5
 *
6
 * Copyright 2015 Sourcefabric z.u. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2015 Sourcefabric z.ú.
12
 * @license http://www.superdesk.org/license
13
 */
14
namespace spec\SWP\MultiTenancyBundle\EventListener;
15
16
use PhpSpec\ObjectBehavior;
17
use SWP\Component\MultiTenancy\Model\Tenant;
18
use Symfony\Component\HttpFoundation\Request;
19
use Symfony\Component\HttpKernel\KernelEvents;
20
use Doctrine\ORM\EntityManagerInterface;
21
use SWP\Component\MultiTenancy\Context\TenantContextInterface;
22
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
23
24
class TenantableListenerSpec extends ObjectBehavior
25
{
26
    public function let(
27
        EntityManagerInterface $entityManager,
28
        TenantContextInterface $tenantContext
29
    ) {
30
        $this->beConstructedWith($entityManager, $tenantContext);
31
    }
32
33
    public function it_is_initializable()
34
    {
35
        $this->shouldHaveType('SWP\MultiTenancyBundle\EventListener\TenantableListener');
36
    }
37
38
    public function it_implements_event_subscriber_interface()
39
    {
40
        $this->shouldImplement('Symfony\Component\EventDispatcher\EventSubscriberInterface');
41
    }
42
43
    public function it_subscribes_to_event()
44
    {
45
        $this::getSubscribedEvents()->shouldReturn([
46
            KernelEvents::REQUEST => 'onKernelRequest',
47
        ]);
48
    }
49
50
    public function it_skips_tenantable_filter_on_kernel_request(
51
        GetResponseEvent $event,
52
        $tenantContext,
53
        $entityManager
54
    ) {
55
        $tenantContext->getTenant()->shouldBeCalled()->willReturn(new Tenant());
56
        $entityManager->getFilters()->shouldNotBeCalled();
57
58
        $this->onKernelRequest($event)->shouldBeNull();
59
    }
60
}
61