Completed
Push — pagerfanta-fix ( 187c46...923c07 )
by Kamil
25:06 queued 03:45
created

RecursiveTransformerSpec   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
lcom 0
cbo 4
dl 0
loc 41
rs 10
c 1
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A let() 0 4 1
A it_is_initializable() 0 4 1
A it_is_data_transformer() 0 4 1
A it_transforms_recursively_using_configured_transformer() 0 8 1
A it_reverse_transforms_using_configured_transformer() 0 8 1
A it_throws_transformation_failed_exception_if_transform_argument_is_not_collection() 0 5 1
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\RecursiveTransformer;
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 RecursiveTransformerSpec extends ObjectBehavior
24
{
25
    function let(DataTransformerInterface $decoratedTransformer)
26
    {
27
        $this->beConstructedWith($decoratedTransformer);
28
    }
29
30
    function it_is_initializable()
31
    {
32
        $this->shouldHaveType(RecursiveTransformer::class);
33
    }
34
35
    function it_is_data_transformer()
36
    {
37
        $this->shouldImplement(DataTransformerInterface::class);
38
    }
39
40
    function it_transforms_recursively_using_configured_transformer(DataTransformerInterface $decoratedTransformer)
41
    {
42
        $decoratedTransformer->transform('ABC')->willReturn('abc');
43
        $decoratedTransformer->transform('CDE')->willReturn('cde');
44
        $decoratedTransformer->transform('FGH')->willReturn('fgh');
45
46
        $this->transform(new ArrayCollection(['ABC', 'CDE', 'FGH']))->shouldBeLike(new ArrayCollection(['abc', 'cde', 'fgh']));
47
    }
48
49
    function it_reverse_transforms_using_configured_transformer(DataTransformerInterface $decoratedTransformer)
50
    {
51
        $decoratedTransformer->reverseTransform('abc')->willReturn('ABC');
52
        $decoratedTransformer->reverseTransform('cde')->willReturn('CDE');
53
        $decoratedTransformer->reverseTransform('fgh')->willReturn('FGH');
54
55
        $this->reverseTransform(new ArrayCollection(['abc', 'cde', 'fgh']))->shouldBeLike(new ArrayCollection(['ABC', 'CDE', 'FGH']));
56
    }
57
58
    function it_throws_transformation_failed_exception_if_transform_argument_is_not_collection()
59
    {
60
        $this->shouldThrow(TransformationFailedException::class)->during('transform', [new \stdClass()]);
61
        $this->shouldThrow(TransformationFailedException::class)->during('reverseTransform', [new \stdClass()]);
62
    }
63
}
64