From 1a53b121aa85d7e8f71f1816f74011e8492ff92f Mon Sep 17 00:00:00 2001 From: Benjamin Grandfond Date: Sun, 30 Sep 2012 10:47:54 +0200 Subject: [PATCH] [2.0][http-foundation] Fix Response::getDate method --- src/Symfony/Component/HttpFoundation/HeaderBag.php | 4 +++- src/Symfony/Component/HttpFoundation/Response.php | 2 +- tests/Symfony/Tests/Component/HttpFoundation/ResponseTest.php | 4 ++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpFoundation/HeaderBag.php b/src/Symfony/Component/HttpFoundation/HeaderBag.php index a212f065e0af..b0f0536c457e 100644 --- a/src/Symfony/Component/HttpFoundation/HeaderBag.php +++ b/src/Symfony/Component/HttpFoundation/HeaderBag.php @@ -226,7 +226,9 @@ public function remove($key) * @param string $key The parameter key * @param \DateTime $default The default value * - * @return \DateTime The filtered value + * @return null|\DateTime The filtered value + * + * @throws \RuntimeException When the HTTP header is not parseable * * @api */ diff --git a/src/Symfony/Component/HttpFoundation/Response.php b/src/Symfony/Component/HttpFoundation/Response.php index bb729f7cbfd6..7b68c3861f0d 100644 --- a/src/Symfony/Component/HttpFoundation/Response.php +++ b/src/Symfony/Component/HttpFoundation/Response.php @@ -430,7 +430,7 @@ public function mustRevalidate() */ public function getDate() { - return $this->headers->getDate('Date'); + return $this->headers->getDate('Date', new \DateTime()); } /** diff --git a/tests/Symfony/Tests/Component/HttpFoundation/ResponseTest.php b/tests/Symfony/Tests/Component/HttpFoundation/ResponseTest.php index a9acc7080c22..689e4b077e32 100644 --- a/tests/Symfony/Tests/Component/HttpFoundation/ResponseTest.php +++ b/tests/Symfony/Tests/Component/HttpFoundation/ResponseTest.php @@ -40,6 +40,10 @@ public function testGetDate() $now = $this->createDateTimeNow(); $response->headers->set('Date', $now->format(DATE_RFC2822)); $this->assertEquals(0, $now->diff($response->getDate())->format('%s'), '->getDate() returns the date when the header has been modified'); + + $response = new Response('', 200); + $response->headers->remove('Date'); + $this->assertInstanceOf('\DateTime', $response->getDate()); } public function testGetMaxAge()