| 1 | <?php |
||
| 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 |