1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Superdesk Web Publisher MultiTenancy Bundle. |
5
|
|
|
* |
6
|
|
|
* Copyright 2016 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 2016 Sourcefabric z.ú |
12
|
|
|
* @license http://www.superdesk.org/license |
13
|
|
|
*/ |
14
|
|
|
|
15
|
|
|
namespace spec\SWP\Bundle\MultiTenancyBundle\Context; |
16
|
|
|
|
17
|
|
|
use PhpSpec\ObjectBehavior; |
18
|
|
|
use SWP\Component\MultiTenancy\Model\TenantInterface; |
19
|
|
|
use SWP\Component\MultiTenancy\Resolver\TenantResolverInterface; |
20
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
21
|
|
|
use Symfony\Component\HttpFoundation\Request; |
22
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
23
|
|
|
|
24
|
|
|
class TenantContextSpec extends ObjectBehavior |
25
|
|
|
{ |
26
|
|
|
public function let( |
27
|
|
|
TenantResolverInterface $tenantResolver, |
28
|
|
|
RequestStack $requestStack, |
29
|
|
|
EventDispatcherInterface $eventDispatcher |
30
|
|
|
) { |
31
|
|
|
$this->beConstructedWith($tenantResolver, $requestStack, $eventDispatcher); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function it_is_initializable() |
35
|
|
|
{ |
36
|
|
|
$this->shouldHaveType('SWP\Bundle\MultiTenancyBundle\Context\TenantContext'); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function it_implements_tenant_context_interface() |
40
|
|
|
{ |
41
|
|
|
$this->shouldImplement('SWP\Component\MultiTenancy\Context\TenantContextInterface'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
View Code Duplication |
public function it_should_set_tenant(TenantInterface $tenant) |
|
|
|
|
45
|
|
|
{ |
46
|
|
|
$tenant->getId()->willReturn(1); |
47
|
|
|
$tenant->getSubdomain()->willReturn('example1'); |
48
|
|
|
$tenant->getName()->willReturn('example1'); |
49
|
|
|
|
50
|
|
|
$this->setTenant($tenant)->shouldBeNull(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function it_should_resolve_tenant_from_request( |
54
|
|
|
$requestStack, |
55
|
|
|
Request $request, |
56
|
|
|
$tenantResolver, |
57
|
|
|
TenantInterface $tenant |
58
|
|
|
) { |
59
|
|
|
$requestStack->getCurrentRequest()->willReturn($request); |
60
|
|
|
$request->getHost()->shouldBeCalled()->willReturn('example.com'); |
61
|
|
|
$request->getRequestUri()->willReturn('/'); |
62
|
|
|
$tenant->getId()->willReturn(1); |
63
|
|
|
$tenant->getSubdomain()->willReturn('default'); |
64
|
|
|
$tenant->getName()->willReturn('Default'); |
65
|
|
|
$tenantResolver->resolve('example.com')->willReturn($tenant); |
66
|
|
|
|
67
|
|
|
$this->getTenant()->shouldReturn($tenant); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function it_should_get_default_tenant_when_no_host_found( |
71
|
|
|
$tenantResolver, |
72
|
|
|
$requestStack, |
73
|
|
|
TenantInterface $tenant |
74
|
|
|
) { |
75
|
|
|
$requestStack->getCurrentRequest()->willReturn(null); |
76
|
|
|
$tenant->getId()->willReturn(1); |
77
|
|
|
$tenant->getSubdomain()->willReturn('default'); |
78
|
|
|
$tenant->getName()->willReturn('Default'); |
79
|
|
|
$tenantResolver->resolve(null)->willReturn($tenant); |
80
|
|
|
|
81
|
|
|
$this->getTenant()->shouldReturn($tenant); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
View Code Duplication |
public function it_should_get_tenant(TenantInterface $tenant) |
|
|
|
|
85
|
|
|
{ |
86
|
|
|
$tenant->getId()->willReturn(1); |
87
|
|
|
$tenant->getSubdomain()->willReturn('example1'); |
88
|
|
|
$tenant->getName()->willReturn('example1'); |
89
|
|
|
|
90
|
|
|
$this->setTenant($tenant)->shouldBeNull(); |
91
|
|
|
$this->getTenant()->shouldEqual($tenant); |
92
|
|
|
} |
93
|
|
|
} |
94
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.