Skip to content
Permalink
Browse files

Add getEncoding()

This gives a more consistent name with the rest of the PSR7 interface
methods.
  • Loading branch information...
markstory committed May 12, 2016
1 parent 3f58c7d commit aa90dcef423c2127f41ef6960668898ae484e10a
Showing with 35 additions and 0 deletions.
  1. +11 −0 src/Http/Client/Response.php
  2. +24 −0 tests/TestCase/Network/Http/ResponseTest.php
@@ -332,8 +332,19 @@ public function getReasonPhrase()
* Get the encoding if it was set.
*
* @return string|null
* @deprecated 3.3.0 Use getEncoding() instead.
*/
public function encoding()
{
return $this->getEncoding();
}
/**
* Get the encoding if it was set.
*
* @return string|null
*/
public function getEncoding()
{
$content = $this->getHeaderLine('content-type');
if (!$content) {
@@ -146,6 +146,16 @@ public function testBodyJson()
$this->assertSame('', $response->json);
}
/**
* Test accessor for json
*
* @return void
*/
public function testBodyJsonPsr7()
{
$this->markTestIncomplete();
}
/**
* Test accessor for xml
*
@@ -278,6 +288,16 @@ public function testCookie()
);
}
/**
* Test accessing cookies set through the PSR7 interface.
*
* @return void
*/
public function testCookiesPsr7()
{
$this->markTestIncomplete();
}
/**
* Test statusCode()
*
@@ -291,6 +311,7 @@ public function testStatusCode()
];
$response = new Response($headers, '');
$this->assertEquals(404, $response->statusCode());
$this->assertEquals(404, $response->getStatusCode());
$this->assertEquals(404, $response->code);
$this->assertTrue(isset($response->code));
@@ -314,20 +335,23 @@ public function testEncoding()
'Content-Type: text/html'
];
$response = new Response($headers, '');
$this->assertNull($response->getEncoding());
$this->assertNull($response->encoding());
$headers = [
'HTTP/1.0 200 Ok',
'Content-Type: text/html; charset="UTF-8"'
];
$response = new Response($headers, '');
$this->assertEquals('UTF-8', $response->getEncoding());
$this->assertEquals('UTF-8', $response->encoding());
$headers = [
'HTTP/1.0 200 Ok',
"Content-Type: text/html; charset='ISO-8859-1'"
];
$response = new Response($headers, '');
$this->assertEquals('ISO-8859-1', $response->getEncoding());
$this->assertEquals('ISO-8859-1', $response->encoding());
}

0 comments on commit aa90dce

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