From 68b544f47c4c2256e38132933d9a160482c46385 Mon Sep 17 00:00:00 2001 From: heik Date: Tue, 3 Sep 2013 16:39:49 +0200 Subject: [PATCH] Http/Client: using injected response object --- library/Zend/Http/Client.php | 2 +- tests/ZendTest/Http/ClientTest.php | 44 +++++++++++++++++++ tests/ZendTest/Http/_files/CustomResponse.php | 7 +++ 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 tests/ZendTest/Http/_files/CustomResponse.php diff --git a/library/Zend/Http/Client.php b/library/Zend/Http/Client.php index be3790477ec..4b67e4d1a3f 100644 --- a/library/Zend/Http/Client.php +++ b/library/Zend/Http/Client.php @@ -905,7 +905,7 @@ public function send(Request $request = null) $response->setCleanup(true); } } else { - $response = Response::fromString($response); + $response = $this->getResponse()->fromString($response); } // Get the cookies from response (if any) diff --git a/tests/ZendTest/Http/ClientTest.php b/tests/ZendTest/Http/ClientTest.php index 453f1985555..3b7cadeeda6 100644 --- a/tests/ZendTest/Http/ClientTest.php +++ b/tests/ZendTest/Http/ClientTest.php @@ -349,4 +349,48 @@ public function testAdapterAlwaysReachableIfSpecified() $this->assertSame($testAdapter, $client->getAdapter()); } + + /** + * Custom response object is set but still invalid code coming back + * @expectedException Zend\Http\Exception\InvalidArgumentException + */ + public function testUsageOfCustomResponseInvalidCode() + { + require_once(dirname(realpath(__FILE__)) . DIRECTORY_SEPARATOR .'_files' . DIRECTORY_SEPARATOR . 'CustomResponse.php'); + $testAdapter = new Test(); + $testAdapter->setResponse( + "HTTP/1.1 496 CustomResponse\r\n\r\n" + . "Whatever content" + ); + + $client = new Client('http://www.example.org/', array( + 'adapter' => $testAdapter, + )); + $client->setResponse(new CustomResponse()); + $response = $client->send(); + } + + /** + * Custom response object is set with defined status code 497. + * Should not throw an exception. + */ + public function testUsageOfCustomResponseCustomCode() + { + require_once(dirname(realpath(__FILE__)) . DIRECTORY_SEPARATOR .'_files' . DIRECTORY_SEPARATOR . 'CustomResponse.php'); + $testAdapter = new Test(); + $testAdapter->setResponse( + "HTTP/1.1 497 CustomResponse\r\n\r\n" + . "Whatever content" + ); + + $client = new Client('http://www.example.org/', array( + 'adapter' => $testAdapter, + )); + $client->setResponse(new CustomResponse()); + $response = $client->send(); + + $this->assertInstanceOf('ZendTest\Http\CustomResponse', $response); + $this->assertEquals(497, $response->getStatusCode()); + $this->assertEquals('Whatever content', $response->getContent()); + } } diff --git a/tests/ZendTest/Http/_files/CustomResponse.php b/tests/ZendTest/Http/_files/CustomResponse.php new file mode 100644 index 00000000000..b45cbd1297e --- /dev/null +++ b/tests/ZendTest/Http/_files/CustomResponse.php @@ -0,0 +1,7 @@ +