Completed
Push — master ( 81c6e7...6c71bd )
by Piotr
02:30
created

CollectionSpec   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 0
loc 49
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace spec\FSi\Bundle\AdminBundle\Display\Property\Formatter;
4
5
use PhpSpec\ObjectBehavior;
6
use Prophecy\Argument;
7
8
class CollectionSpec extends ObjectBehavior
9
{
10
    /**
11
     * @param \FSi\Bundle\AdminBundle\Display\Property\ValueFormatter $formatter
12
     */
13
    function let($formatter)
14
    {
15
        $this->beConstructedWith(array($formatter));
16
    }
17
18
    function it_ignore_empty_values()
19
    {
20
        $this->format(0)->shouldReturn(0);
21
        $this->format(null)->shouldReturn(null);
22
        $this->format(array())->shouldReturn(array());
23
    }
24
25
    function it_throw_exception_when_value_is_not_an_array()
26
    {
27
        $this->shouldThrow(new \InvalidArgumentException("Collection decorator require value to be an array or implement \\Iterator"))
28
            ->during('format', array(new \stdClass()));
29
    }
30
31
    /**
32
     * @param \FSi\Bundle\AdminBundle\Display\Property\ValueFormatter $formatter
33
     */
34
    function it_format_each_element_of_collection_using_formatters($formatter)
35
    {
36
        $value = array(
37
            'first-date' => new \DateTime(),
38
            'second-date' => new \DateTime()
39
        );
40
        $formatter->format(Argument::any())->will(function($argument) {return $argument[0];});
41
        $this->format($value)->shouldReturn($value);
42
    }
43
44
    /**
45
     * @param \FSi\Bundle\AdminBundle\Display\Property\ValueFormatter $formatter
46
     */
47
    function it_format_each_element_of_iterator_using_formatters($formatter)
48
    {
49
        $value = array(
50
            'first-date' => new \DateTime(),
51
            'second-date' => new \DateTime()
52
        );
53
        $formatter->format(Argument::any())->will(function($argument) {return $argument[0];});
54
        $this->format(new \ArrayIterator($value))->shouldReturn($value);
55
    }
56
}
57