1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the Sylius package. |
5
|
|
|
* |
6
|
|
|
* (c) Paweł Jędrzejewski |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
declare(strict_types=1); |
13
|
|
|
|
14
|
|
|
namespace spec\Sylius\Bundle\ResourceBundle\Form\DataTransformer; |
15
|
|
|
|
16
|
|
|
use PhpSpec\ObjectBehavior; |
17
|
|
|
use Prophecy\Argument; |
18
|
|
|
use Sylius\Bundle\ResourceBundle\Form\DataTransformer\ResourceToIdentifierTransformer; |
19
|
|
|
use Sylius\Component\Resource\Model\ResourceInterface; |
20
|
|
|
use Sylius\Component\Resource\Repository\RepositoryInterface; |
21
|
|
|
use Symfony\Component\Form\Exception\TransformationFailedException; |
22
|
|
|
|
23
|
|
|
final class ResourceToIdentifierTransformerSpec extends ObjectBehavior |
24
|
|
|
{ |
25
|
|
|
function let(RepositoryInterface $repository): void |
26
|
|
|
{ |
27
|
|
|
$this->beConstructedWith($repository, 'id'); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
function it_does_not_reverses_null_value(RepositoryInterface $repository): void |
31
|
|
|
{ |
32
|
|
|
$repository->findOneBy(Argument::any())->shouldNotBeCalled(); |
33
|
|
|
|
34
|
|
|
$this->reverseTransform(null)->shouldReturn(null); |
35
|
|
|
} |
36
|
|
|
|
37
|
|
|
function it_throws_an_exception_on_non_existing_resource(RepositoryInterface $repository): void |
38
|
|
|
{ |
39
|
|
|
$repository->getClassName()->willReturn(ResourceInterface::class); |
40
|
|
|
$repository->findOneBy(['id' => 6])->willReturn(null); |
41
|
|
|
|
42
|
|
|
$this->shouldThrow(TransformationFailedException::class)->during('reverseTransform', [6]); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
function it_reverse_transform_identifier_to_resource(RepositoryInterface $repository, ResourceInterface $resource): void |
46
|
|
|
{ |
47
|
|
|
$repository->findOneBy(['id' => 5])->willReturn($resource); |
48
|
|
|
|
49
|
|
|
$this->reverseTransform(5)->shouldReturn($resource); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
function it_transforms_null_value_to_empty_string(RepositoryInterface $repository): void |
53
|
|
|
{ |
54
|
|
|
$repository->getClassName()->willReturn(ResourceInterface::class); |
55
|
|
|
|
56
|
|
|
$this->transform(null)->shouldReturn(null); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
function it_transforms_resource_in_identifier(RepositoryInterface $repository, ResourceInterface $resource): void |
60
|
|
|
{ |
61
|
|
|
$repository->getClassName()->willReturn(ResourceInterface::class); |
62
|
|
|
|
63
|
|
|
$resource->getId()->willReturn(6); |
64
|
|
|
|
65
|
|
|
$this->transform($resource)->shouldReturn(6); |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|