[HttpFoundation] fix return types and handling of zero in Response
This commit is contained in:
parent
75952af0c3
commit
10b01c9159
|
@ -614,8 +614,8 @@ class Response
|
|||
*/
|
||||
public function getAge()
|
||||
{
|
||||
if ($age = $this->headers->get('Age')) {
|
||||
return $age;
|
||||
if (null !== $age = $this->headers->get('Age')) {
|
||||
return (int) $age;
|
||||
}
|
||||
|
||||
return max(time() - $this->getDate()->format('U'), 0);
|
||||
|
@ -691,12 +691,12 @@ class Response
|
|||
*/
|
||||
public function getMaxAge()
|
||||
{
|
||||
if ($age = $this->headers->getCacheControlDirective('s-maxage')) {
|
||||
return $age;
|
||||
if ($this->headers->hasCacheControlDirective('s-maxage')) {
|
||||
return (int) $this->headers->getCacheControlDirective('s-maxage');
|
||||
}
|
||||
|
||||
if ($age = $this->headers->getCacheControlDirective('max-age')) {
|
||||
return $age;
|
||||
if ($this->headers->hasCacheControlDirective('max-age')) {
|
||||
return (int) $this->headers->getCacheControlDirective('max-age');
|
||||
}
|
||||
|
||||
if (null !== $this->getExpires()) {
|
||||
|
@ -757,7 +757,7 @@ class Response
|
|||
*/
|
||||
public function getTtl()
|
||||
{
|
||||
if ($maxAge = $this->getMaxAge()) {
|
||||
if (null !== $maxAge = $this->getMaxAge()) {
|
||||
return $maxAge - $this->getAge();
|
||||
}
|
||||
|
||||
|
@ -961,7 +961,7 @@ class Response
|
|||
*/
|
||||
public function hasVary()
|
||||
{
|
||||
return (Boolean) $this->headers->get('Vary');
|
||||
return null !== $this->headers->get('Vary');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -223,7 +223,7 @@ class ResponseTest extends \PHPUnit_Framework_TestCase
|
|||
$response = new Response();
|
||||
$response->headers->set('Expires', -1);
|
||||
$response->expire();
|
||||
$this->assertEquals(0, $response->headers->get('Age'), '->expire() does not set the Age to 0');
|
||||
$this->assertNull($response->headers->get('Age'), '->expire() does not set the Age when the response is expired');
|
||||
}
|
||||
|
||||
public function testGetTtl()
|
||||
|
@ -237,7 +237,12 @@ class ResponseTest extends \PHPUnit_Framework_TestCase
|
|||
|
||||
$response = new Response();
|
||||
$response->headers->set('Expires', $this->createDateTimeOneHourAgo()->format(DATE_RFC2822));
|
||||
$this->assertLessThan(0, $response->getTtl(), '->getTtl() returns negative values when Expires is in part');
|
||||
$this->assertLessThan(0, $response->getTtl(), '->getTtl() returns negative values when Expires is in past');
|
||||
|
||||
$response = new Response();
|
||||
$response->headers->set('Expires', $response->getDate()->format(DATE_RFC2822));
|
||||
$response->headers->set('Age', 0);
|
||||
$this->assertSame(0, $response->getTtl(), '->getTtl() correctly handles zero');
|
||||
|
||||
$response = new Response();
|
||||
$response->headers->set('Cache-Control', 'max-age=60');
|
||||
|
|
Reference in New Issue