Skip to content
Permalink
Browse files

Add deprecation warnings for Response methods.

I missed these before, but they are part of the mutable interface for
responses that needs to go away.
  • Loading branch information...
markstory committed May 28, 2018
1 parent a6fa365 commit e78cb4a90048b19d4df6e822af64cfd239d1ed17
Showing with 52 additions and 33 deletions.
  1. +10 −0 src/Http/Response.php
  2. +42 −33 tests/TestCase/Http/ResponseTest.php
@@ -1422,11 +1422,16 @@ public function withSharable($public, $time = null)
* a good candidate to be fetched from a shared cache (like in a proxy server).
* If called with no parameters, this function will return the current max-age value if any
*
* @deprecated 3.6.5 Use withSharedMaxAge() instead.
* @param int|null $seconds if null, the method will return the current s-maxage value
* @return int|null
*/
public function sharedMaxAge($seconds = null)
{
deprecationWarning(
'Response::sharedMaxAge() is deprecated. ' .
'Use withSharedMaxAge() instead.'
);
if ($seconds !== null) {
$this->_cacheDirectives['s-maxage'] = $seconds;
$this->_setCacheControl();
@@ -1462,11 +1467,16 @@ public function withSharedMaxAge($seconds)
* a good candidate to be fetched from the local (client) cache.
* If called with no parameters, this function will return the current max-age value if any
*
* @deprecated 3.6.5 Use withMaxAge() instead.
* @param int|null $seconds if null, the method will return the current max-age value
* @return int|null
*/
public function maxAge($seconds = null)
{
deprecationWarning(
'Response::maxAge() is deprecated. ' .
'Use withMaxAge() instead.'
);
if ($seconds !== null) {
$this->_cacheDirectives['max-age'] = $seconds;
$this->_setCacheControl();
@@ -1074,28 +1074,31 @@ public function testWithModified()
/**
* Tests setting of public/private Cache-Control directives
*
* @deprecated
* @return void
*/
public function testSharable()
{
$response = new Response();
$this->assertNull($response->sharable());
$response->sharable(true);
$this->assertTrue($response->sharable());
$this->assertEquals('public', $response->getHeaderLine('Cache-Control'));
$this->deprecated(function () {
$response = new Response();
$this->assertNull($response->sharable());
$response->sharable(true);
$this->assertTrue($response->sharable());
$this->assertEquals('public', $response->getHeaderLine('Cache-Control'));
$response = new Response();
$response->sharable(false);
$this->assertFalse($response->sharable());
$this->assertEquals('private', $response->getHeaderLine('Cache-Control'));
$response = new Response();
$response->sharable(false);
$this->assertFalse($response->sharable());
$this->assertEquals('private', $response->getHeaderLine('Cache-Control'));
$response = new Response();
$response->sharable(true, 3600);
$this->assertEquals('public, max-age=3600', $response->getHeaderLine('Cache-Control'));
$response = new Response();
$response->sharable(true, 3600);
$this->assertEquals('public, max-age=3600', $response->getHeaderLine('Cache-Control'));
$response = new Response();
$response->sharable(false, 3600);
$this->assertEquals('private, max-age=3600', $response->getHeaderLine('Cache-Control'));
$response = new Response();
$response->sharable(false, 3600);
$this->assertEquals('private, max-age=3600', $response->getHeaderLine('Cache-Control'));
});
}
/**
@@ -1123,20 +1126,23 @@ public function testWithSharable()
/**
* Tests setting of max-age Cache-Control directive
*
* @deprecated
* @return void
*/
public function testMaxAge()
{
$response = new Response();
$this->assertNull($response->maxAge());
$response->maxAge(3600);
$this->assertEquals(3600, $response->maxAge());
$this->assertEquals('max-age=3600', $response->getHeaderLine('Cache-Control'));
$this->deprecated(function () {
$response = new Response();
$this->assertNull($response->maxAge());
$response->maxAge(3600);
$this->assertEquals(3600, $response->maxAge());
$this->assertEquals('max-age=3600', $response->getHeaderLine('Cache-Control'));
$response = new Response();
$response->maxAge(3600);
$response->sharable(false);
$this->assertEquals('max-age=3600, private', $response->getHeaderLine('Cache-Control'));
$response = new Response();
$response->maxAge(3600);
$response->sharable(false);
$this->assertEquals('max-age=3600, private', $response->getHeaderLine('Cache-Control'));
});
}
/**
@@ -1160,20 +1166,23 @@ public function testWithMaxAge()
/**
* Tests setting of s-maxage Cache-Control directive
*
* @deprecated
* @return void
*/
public function testSharedMaxAge()
{
$response = new Response();
$this->assertNull($response->maxAge());
$response->sharedMaxAge(3600);
$this->assertEquals(3600, $response->sharedMaxAge());
$this->assertEquals('s-maxage=3600', $response->getHeaderLine('Cache-Control'));
$this->deprecated(function () {
$response = new Response();
$this->assertNull($response->maxAge());
$response->sharedMaxAge(3600);
$this->assertEquals(3600, $response->sharedMaxAge());
$this->assertEquals('s-maxage=3600', $response->getHeaderLine('Cache-Control'));
$response = new Response();
$response->sharedMaxAge(3600);
$response->sharable(true);
$this->assertEquals('s-maxage=3600, public', $response->getHeaderLine('Cache-Control'));
$response = new Response();
$response->sharedMaxAge(3600);
$response->sharable(true);
$this->assertEquals('s-maxage=3600, public', $response->getHeaderLine('Cache-Control'));
});
}
/**

0 comments on commit e78cb4a

Please sign in to comment.
You can’t perform that action at this time.