Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit f49fbc3

Browse filesBrowse files
committed
Add test and fix typo
1 parent f047a26 commit f49fbc3
Copy full SHA for f49fbc3

File tree

2 files changed

+15
-3
lines changed
Filter options

2 files changed

+15
-3
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Normalizer/DateTimeNormalizer.php
+5-1Lines 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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Serializer/Tests/Normalizer/DateTimeNormalizerTest.php
+10-2Lines 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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.