Skip to content

Commit f49fbc3

Browse files
committed
Add test and fix typo
1 parent f047a26 commit f49fbc3

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,13 @@ public function __construct($format = \DateTime::RFC3339)
3939

4040
/**
4141
* {@inheritdoc}
42+
*
43+
* @throws InvalidArgumentException
4244
*/
4345
public function normalize($object, $format = null, array $context = array())
4446
{
4547
if (!$object instanceof \DateTimeInterface) {
46-
throw new InvalidArgumentException('The object must implements the "\DateTimeInterface".');
48+
throw new InvalidArgumentException('The object must implement the "\DateTimeInterface".');
4749
}
4850

4951
$format = isset($context[self::FORMAT_KEY]) ? $context[self::FORMAT_KEY] : $this->format;
@@ -61,6 +63,8 @@ public function supportsNormalization($data, $format = null)
6163

6264
/**
6365
* {@inheritdoc}
66+
*
67+
* @throws UnexpectedValueException
6468
*/
6569
public function denormalize($data, $class, $format = null, array $context = array())
6670
{

src/Symfony/Component/Serializer/Tests/Normalizer/DateTimeNormalizerTest.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ public function testConstructorFormat()
5252
}
5353

5454
/**
55-
* @expectedException InvalidArgumentException
56-
* @expectedExceptionMessage The object must implements the "\DateTimeInterface".
55+
* @expectedException \Symfony\Component\Serializer\Exception\InvalidArgumentException
56+
* @expectedExceptionMessage The object must implement the "\DateTimeInterface".
5757
*/
5858
public function testInvalidDataThrowException()
5959
{
@@ -74,4 +74,12 @@ public function testDenormalize()
7474
$this->assertEquals(new \DateTimeImmutable('2016/01/01'), $this->normalizer->denormalize('2016-01-01T00:00:00+00:00', \DateTimeImmutable::class));
7575
$this->assertEquals(new \DateTime('2016/01/01'), $this->normalizer->denormalize('2016-01-01T00:00:00+00:00', \DateTime::class));
7676
}
77+
78+
/**
79+
* @expectedException \Symfony\Component\Serializer\Exception\UnexpectedValueException
80+
*/
81+
public function testInvalidDateThrowException()
82+
{
83+
$this->normalizer->denormalize('invalid date', \DateTimeInterface::class);
84+
}
7785
}

0 commit comments

Comments
 (0)