Completed
Pull Request — master (#1)
by Rafał
10:37
created

TenantListenerSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 7 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 20 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 SWP\Component\MultiTenancy\Resolver\TenantResolverInterface;
19
use Symfony\Component\HttpFoundation\Request;
20
use Symfony\Component\HttpKernel\KernelEvents;
21
use Doctrine\ORM\EntityManagerInterface;
22
use SWP\Component\MultiTenancy\Context\TenantContextInterface;
23
use Symfony\Component\HttpKernel\Event\GetResponseEvent;
24
25
class TenantListenerSpec extends ObjectBehavior
26
{
27
    public function let(
28
        EntityManagerInterface $entityManager,
29
        TenantContextInterface $tenantContext,
30
        TenantResolverInterface $tenantResolver
31
    ) {
32
        $this->beConstructedWith($entityManager, $tenantContext, $tenantResolver);
33
    }
34
35
    public function it_is_initializable()
36
    {
37
        $this->shouldHaveType('SWP\MultiTenancyBundle\EventListener\TenantListener');
38
    }
39
40
    public function it_implements_event_subscriber_interface()
41
    {
42
        $this->shouldImplement('Symfony\Component\EventDispatcher\EventSubscriberInterface');
43
    }
44
45
    public function it_subscribes_to_event()
46
    {
47
        $this::getSubscribedEvents()->shouldReturn(array(
48
            KernelEvents::REQUEST => 'onKernelRequest',
49
        ));
50
    }
51
52
    public function it_skips_tenantable_filter_on_kernel_request(
53
        GetResponseEvent $event,
54
        $tenantContext,
55
        Request $request,
56
        TenantResolverInterface $tenantResolver,
57
        $entityManager
58
    ) {
59
        $tenant = new Tenant();
60
        $tenant->setSubdomain('default');
61
        $tenant->setName('Default');
62
63
        $tenantContext->getTenant()->shouldBeCalled()->willReturn(new Tenant());
64
        $entityManager->getFilters()->shouldNotBeCalled();
65
        $request->getHost()->willReturn('example.com');
66
        $event->getRequest()->willReturn($request);
67
        $tenantResolver->resolve('example.com')->willReturn($tenant);
68
        $tenantContext->setTenant($tenant)->shouldBeCalled();
69
70
        $this->onKernelRequest($event)->shouldBeNull();
71
    }
72
}
73