Skip to content
This repository
Browse code

merged branch benja-M-1/hotfix-response (PR #5633)

This PR was squashed before being merged into the 2.0 branch (closes #5633).

Commits
-------

5c60a65 [2.0][http-foundation] Update phpdoc
c17462f [2.0][http-foundation] Fix response getDate method

Discussion
----------

[2.0][http-foundation] Fix Response::getDate method

Bug fix: no
Feature addition: yes
Backwards compatibility break: no
Symfony2 tests pass: yes
License of the code: MIT

Reference #5588, #5629
  • Loading branch information...
commit 302c0e4647100402185d160a814b32e14ac9b37b 2 parents 5984dee + 1a53b12
Fabien Potencier fabpot authored
4 src/Symfony/Component/HttpFoundation/HeaderBag.php
@@ -226,7 +226,9 @@ public function remove($key)
226 226 * @param string $key The parameter key
227 227 * @param \DateTime $default The default value
228 228 *
229   - * @return \DateTime The filtered value
  229 + * @return null|\DateTime The filtered value
  230 + *
  231 + * @throws \RuntimeException When the HTTP header is not parseable
230 232 *
231 233 * @api
232 234 */
2  src/Symfony/Component/HttpFoundation/Response.php
@@ -430,7 +430,7 @@ public function mustRevalidate()
430 430 */
431 431 public function getDate()
432 432 {
433   - return $this->headers->getDate('Date');
  433 + return $this->headers->getDate('Date', new \DateTime());
434 434 }
435 435
436 436 /**
4 tests/Symfony/Tests/Component/HttpFoundation/ResponseTest.php
@@ -40,6 +40,10 @@ public function testGetDate()
40 40 $now = $this->createDateTimeNow();
41 41 $response->headers->set('Date', $now->format(DATE_RFC2822));
42 42 $this->assertEquals(0, $now->diff($response->getDate())->format('%s'), '->getDate() returns the date when the header has been modified');
  43 +
  44 + $response = new Response('', 200);
  45 + $response->headers->remove('Date');
  46 + $this->assertInstanceOf('\DateTime', $response->getDate());
43 47 }
44 48
45 49 public function testGetMaxAge()

0 comments on commit 302c0e4

Please sign in to comment.
Something went wrong with that request. Please try again.