1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
/* |
6
|
|
|
* This file is part of the Superdesk Web Publisher MultiTenancy Bundle. |
7
|
|
|
* |
8
|
|
|
* Copyright 2017 Sourcefabric z.ú. and contributors. |
9
|
|
|
* |
10
|
|
|
* For the full copyright and license information, please see the |
11
|
|
|
* AUTHORS and LICENSE files distributed with this source code. |
12
|
|
|
* |
13
|
|
|
* @copyright 2017 Sourcefabric z.ú. |
14
|
|
|
* @license http://www.superdesk.org/license |
15
|
|
|
*/ |
16
|
|
|
|
17
|
|
|
namespace spec\SWP\Bundle\MultiTenancyBundle\Form\DataTransformer; |
18
|
|
|
|
19
|
|
|
use PhpSpec\ObjectBehavior; |
20
|
|
|
use SWP\Bundle\MultiTenancyBundle\Form\DataTransformer\TenantToCodeTransformer; |
21
|
|
|
use SWP\Component\MultiTenancy\Context\TenantContextInterface; |
22
|
|
|
use SWP\Component\MultiTenancy\Model\TenantInterface; |
23
|
|
|
use SWP\Component\MultiTenancy\Repository\TenantRepositoryInterface; |
24
|
|
|
use Symfony\Component\Form\DataTransformerInterface; |
25
|
|
|
use Symfony\Component\Form\Exception\TransformationFailedException; |
26
|
|
|
use Symfony\Component\Form\Exception\UnexpectedTypeException; |
27
|
|
|
|
28
|
|
|
final class TenantToCodeTransformerSpec extends ObjectBehavior |
29
|
|
|
{ |
30
|
|
|
public function let(TenantRepositoryInterface $tenantRepository, TenantContextInterface $tenantContext) |
31
|
|
|
{ |
32
|
|
|
$this->beConstructedWith($tenantRepository, $tenantContext); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function it_is_initializable() |
36
|
|
|
{ |
37
|
|
|
$this->shouldHaveType(TenantToCodeTransformer::class); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
public function it_implements_an_interface() |
41
|
|
|
{ |
42
|
|
|
$this->shouldImplement(DataTransformerInterface::class); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
public function it_should_return_null_if_null_transformed() |
46
|
|
|
{ |
47
|
|
|
$this->transform(null)->shouldReturn(null); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
public function it_should_throw_an_exception_when_tenant_not_found() |
51
|
|
|
{ |
52
|
|
|
$this |
53
|
|
|
->shouldThrow(UnexpectedTypeException::class) |
54
|
|
|
->duringTransform(new \stdClass()) |
55
|
|
|
; |
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function it_should_transform_tenant_to_code(TenantInterface $tenant) |
59
|
|
|
{ |
60
|
|
|
$tenant->getId()->willReturn('123abc'); |
61
|
|
|
|
62
|
|
|
$this->transform($tenant)->shouldReturn('123abc'); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function it_should_return_null_if_null_reverse_transformed() |
66
|
|
|
{ |
67
|
|
|
$this->reverseTransform(null)->shouldReturn(null); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function it_should_throw_an_exception_during_reverse_transform() |
71
|
|
|
{ |
72
|
|
|
$this |
73
|
|
|
->shouldThrow(TransformationFailedException::class) |
74
|
|
|
->duringReverseTransform('') |
75
|
|
|
; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public function it_should_reverse_transform_id_to_route( |
79
|
|
|
TenantRepositoryInterface $tenantRepository, |
80
|
|
|
TenantInterface $tenant, |
81
|
|
|
TenantContextInterface $tenantContext |
82
|
|
|
) { |
83
|
|
|
$tenantRepository->findOneByCode('123abc')->willReturn($tenant); |
84
|
|
|
$tenantContext->setTenant($tenant)->shouldBeCalled(); |
85
|
|
|
|
86
|
|
|
$this->reverseTransform('123abc')->shouldReturn($tenant); |
87
|
|
|
} |
88
|
|
|
} |
89
|
|
|
|