1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace spec\Xabbuh\XApi\Serializer\Normalizer; |
4
|
|
|
|
5
|
|
|
use PhpSpec\ObjectBehavior; |
6
|
|
|
|
7
|
|
|
class TimestampNormalizerSpec extends ObjectBehavior |
8
|
|
|
{ |
9
|
|
|
function it_is_a_normalizer() |
10
|
|
|
{ |
11
|
|
|
$this->shouldHaveType('Symfony\Component\Serializer\Normalizer\NormalizerInterface'); |
12
|
|
|
} |
13
|
|
|
|
14
|
|
|
function it_can_normalize_datetime_objects() |
15
|
|
|
{ |
16
|
|
|
$this->supportsNormalization(new \DateTime())->shouldBe(true); |
17
|
|
|
} |
18
|
|
|
|
19
|
|
|
function it_cannot_normalize_datetime_like_string() |
20
|
|
|
{ |
21
|
|
|
$this->supportsNormalization('2004-02-12T15:19:21+00:00')->shouldBe(false); |
22
|
|
|
} |
23
|
|
|
|
24
|
|
|
function it_normalizes_datetime_objects_as_iso_8601_formatted_strings() |
25
|
|
|
{ |
26
|
|
|
$date = new \DateTime(); |
27
|
|
|
$date->setTimezone(new \DateTimeZone('UTC')); |
28
|
|
|
$date->setDate(2004, 2, 12); |
29
|
|
|
$date->setTime(15, 19, 21); |
30
|
|
|
|
31
|
|
|
$this->normalize($date)->shouldReturn('2004-02-12T15:19:21+00:00'); |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
function it_throws_an_exception_when_data_other_than_datetime_objects_are_passed() |
35
|
|
|
{ |
36
|
|
|
$this->shouldThrow('Symfony\Component\Serializer\Exception\InvalidArgumentException')->during('normalize', array('2004-02-12T15:19:21+00:00')); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
function it_is_a_denormalizer() |
40
|
|
|
{ |
41
|
|
|
$this->shouldHaveType('Symfony\Component\Serializer\Normalizer\DenormalizerInterface'); |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
function it_can_denormalize_to_datetime_objects() |
45
|
|
|
{ |
46
|
|
|
$this->supportsDenormalization('2004-02-12T15:19:21+00:00', 'DateTime')->shouldBe(true); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
function it_denormalizes_iso_8601_formatted_strings_to_datetime_objects() |
50
|
|
|
{ |
51
|
|
|
$date = $this->denormalize('2004-02-12T15:19:21+00:00', 'DateTime'); |
52
|
|
|
|
53
|
|
|
$date->getTimezone()->shouldBeLike(new \DateTimeZone('UTC')); |
54
|
|
|
$date->format('Y-m-d H:i:s')->shouldReturn('2004-02-12 15:19:21'); |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|