Completed
Push — master ( 5503b7...fc88fd )
by Kamil
19:37
created

CollectionToStringTransformerSpec::let()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
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
namespace spec\Sylius\Bundle\ResourceBundle\Form\DataTransformer;
13
14
use Doctrine\Common\Collections\ArrayCollection;
15
use PhpSpec\ObjectBehavior;
16
use Sylius\Bundle\ResourceBundle\Form\DataTransformer\CollectionToStringTransformer;
17
use Symfony\Component\Form\DataTransformerInterface;
18
use Symfony\Component\Form\Exception\TransformationFailedException;
19
20
/**
21
 * @author Arkadiusz Krakowiak <[email protected]>
22
 */
23
final class CollectionToStringTransformerSpec extends ObjectBehavior
24
{
25
    function let()
26
    {
27
        $this->beConstructedWith(',');
28
    }
29
30
    function it_is_initializable()
31
    {
32
        $this->shouldHaveType(CollectionToStringTransformer::class);
33
    }
34
35
    function it_is_data_transformer()
36
    {
37
        $this->shouldImplement(DataTransformerInterface::class);
38
    }
39
40
    function it_transforms_collection_to_string()
41
    {
42
        $this->transform(new ArrayCollection(['abc', 'def', 'ghi', 'jkl']))->shouldReturn('abc,def,ghi,jkl');
43
    }
44
45
    function it_transforms_string_to_collection()
46
    {
47
        $this->reverseTransform('abc,def,ghi,jkl')->shouldBeLike(new ArrayCollection(['abc', 'def', 'ghi', 'jkl']));
48
    }
49
50
    function it_throws_transformation_failed_exception_if_transform_argument_is_not_a_collection()
51
    {
52
        $this->shouldThrow(TransformationFailedException::class)->during('transform', [new \stdClass()]);
53
    }
54
55
    function it_throws_transformation_failed_exception_if_transform_argument_is_not_a_string()
56
    {
57
        $this->shouldThrow(TransformationFailedException::class)->during('reverseTransform', [new \stdClass()]);
58
    }
59
60
    function it_returns_empty_string_if_empty_collection_given()
61
    {
62
        $this->transform(new ArrayCollection())->shouldReturn('');
63
    }
64
65
    function it_returns_empty_collection_if_empty_string_given()
66
    {
67
        $this->reverseTransform('')->shouldBeLike(new ArrayCollection());
68
    }
69
}
70