1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is part of the Superdesk Web Publisher MultiTenancy Component. |
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\Component\MultiTenancy\Resolver; |
15
|
|
|
|
16
|
|
|
use PhpSpec\ObjectBehavior; |
17
|
|
|
use SWP\Component\MultiTenancy\Model\TenantInterface; |
18
|
|
|
use SWP\Component\MultiTenancy\Repository\TenantRepositoryInterface; |
19
|
|
|
|
20
|
|
|
class TenantResolverSpec extends ObjectBehavior |
21
|
|
|
{ |
22
|
|
|
public function let(TenantRepositoryInterface $tenantRepository) |
23
|
|
|
{ |
24
|
|
|
$this->beConstructedWith('domain.com', $tenantRepository); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function it_is_initializable() |
28
|
|
|
{ |
29
|
|
|
$this->shouldHaveType('SWP\Component\MultiTenancy\Resolver\TenantResolver'); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
public function it_implements_tenant_resolver_interface() |
33
|
|
|
{ |
34
|
|
|
$this->shouldImplement('SWP\Component\MultiTenancy\Resolver\TenantResolverInterface'); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
View Code Duplication |
public function it_resolves_tenant_from_subdomain($tenantRepository, TenantInterface $tenant) |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
$tenant->getId()->willReturn(1); |
40
|
|
|
$tenant->getSubdomain()->willReturn('example1'); |
41
|
|
|
$tenant->getName()->willReturn('example1'); |
42
|
|
|
|
43
|
|
|
$tenantRepository->findBySubdomain('example1') |
44
|
|
|
->shouldBeCalled() |
45
|
|
|
->willReturn($tenant); |
46
|
|
|
|
47
|
|
|
$this->resolve('example1.domain.com')->shouldReturn($tenant); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
View Code Duplication |
public function it_resolves_tenant_from_default_root_host($tenantRepository, TenantInterface $tenant) |
|
|
|
|
51
|
|
|
{ |
52
|
|
|
$tenant->getId()->willReturn(1); |
53
|
|
|
$tenant->getSubdomain()->willReturn('default'); |
54
|
|
|
$tenant->getName()->willReturn('default'); |
55
|
|
|
|
56
|
|
|
$tenantRepository->findBySubdomain('default') |
57
|
|
|
->shouldBeCalled() |
58
|
|
|
->willReturn($tenant); |
59
|
|
|
|
60
|
|
|
$this->resolve('domain.com')->shouldReturn($tenant); |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
|
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.