Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Jan 30, 2020. It is now read-only.

Commit 0a4d9f4

Browse files
committed
Merge pull request zendframework/zendframework#5068 from heik/master
using injected response object

3 files changed

Lines changed: 52 additions & 1 deletion

File tree

src/Client.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -905,7 +905,7 @@ public function send(Request $request = null)
905905
$response->setCleanup(true);
906906
}
907907
} else {
908-
$response = Response::fromString($response);
908+
$response = $this->getResponse()->fromString($response);
909909
}
910910

911911
// Get the cookies from response (if any)

test/ClientTest.php

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,4 +349,48 @@ public function testAdapterAlwaysReachableIfSpecified()
349349

350350
$this->assertSame($testAdapter, $client->getAdapter());
351351
}
352+
353+
/**
354+
* Custom response object is set but still invalid code coming back
355+
* @expectedException Zend\Http\Exception\InvalidArgumentException
356+
*/
357+
public function testUsageOfCustomResponseInvalidCode()
358+
{
359+
require_once(dirname(realpath(__FILE__)) . DIRECTORY_SEPARATOR .'_files' . DIRECTORY_SEPARATOR . 'CustomResponse.php');
360+
$testAdapter = new Test();
361+
$testAdapter->setResponse(
362+
"HTTP/1.1 496 CustomResponse\r\n\r\n"
363+
. "Whatever content"
364+
);
365+
366+
$client = new Client('http://www.example.org/', array(
367+
'adapter' => $testAdapter,
368+
));
369+
$client->setResponse(new CustomResponse());
370+
$response = $client->send();
371+
}
372+
373+
/**
374+
* Custom response object is set with defined status code 497.
375+
* Should not throw an exception.
376+
*/
377+
public function testUsageOfCustomResponseCustomCode()
378+
{
379+
require_once(dirname(realpath(__FILE__)) . DIRECTORY_SEPARATOR .'_files' . DIRECTORY_SEPARATOR . 'CustomResponse.php');
380+
$testAdapter = new Test();
381+
$testAdapter->setResponse(
382+
"HTTP/1.1 497 CustomResponse\r\n\r\n"
383+
. "Whatever content"
384+
);
385+
386+
$client = new Client('http://www.example.org/', array(
387+
'adapter' => $testAdapter,
388+
));
389+
$client->setResponse(new CustomResponse());
390+
$response = $client->send();
391+
392+
$this->assertInstanceOf('ZendTest\Http\CustomResponse', $response);
393+
$this->assertEquals(497, $response->getStatusCode());
394+
$this->assertEquals('Whatever content', $response->getContent());
395+
}
352396
}

test/_files/CustomResponse.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?php
2+
namespace ZendTest\Http;
3+
4+
class CustomResponse extends \Zend\Http\Response
5+
{
6+
const STATUS_CODE_497 = 497;
7+
}

0 commit comments

Comments
 (0)