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

Lines changed: 5 additions & 1 deletion
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

Lines changed: 10 additions & 2 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy