Test custom cURL options in Client

This commit is contained in:
PJ Dietz 2014-07-25 23:27:24 -04:00
parent 3d44d1a3f5
commit c9c21fd22e
1 changed files with 61 additions and 0 deletions

View File

@ -137,4 +137,65 @@ class ClientTest extends \PHPUnit_Framework_TestCase
[$faker->text()]
];
}
public function testSetCustomCurlOptionsOnInstantiation()
{
$host = "localhost";
$port = 8080;
$script = realpath(__DIR__ . "/sham-routers/headers.php");
$server = new ShamServer($host, $port, $script);
$rqst = $this->getMockBuilder('pjdietz\WellRESTed\Interfaces\RequestInterface')->getMock();
$rqst->expects($this->any())
->method("getUri")
->will($this->returnValue("http://$host:$port"));
$rqst->expects($this->any())
->method("getMethod")
->will($this->returnValue("GET"));
$rqst->expects($this->any())
->method("getPort")
->will($this->returnValue($port));
$rqst->expects($this->any())
->method("getHeaders")
->will($this->returnValue(array()));
$cookieValue = "key=value";
$client = new Client([CURLOPT_COOKIE => $cookieValue]);
$resp = $client->request($rqst);
$headers = json_decode($resp->getBody());
$this->assertEquals($cookieValue, $headers->Cookie);
$server->stop();
}
public function testSetCustomCurlOptionsOnRequest()
{
$host = "localhost";
$port = 8080;
$script = realpath(__DIR__ . "/sham-routers/headers.php");
$server = new ShamServer($host, $port, $script);
$rqst = $this->getMockBuilder('pjdietz\WellRESTed\Interfaces\RequestInterface')->getMock();
$rqst->expects($this->any())
->method("getUri")
->will($this->returnValue("http://$host:$port"));
$rqst->expects($this->any())
->method("getMethod")
->will($this->returnValue("GET"));
$rqst->expects($this->any())
->method("getPort")
->will($this->returnValue($port));
$rqst->expects($this->any())
->method("getHeaders")
->will($this->returnValue(array()));
$cookieValue = "key=value";
$client = new Client();
$resp = $client->request($rqst, [CURLOPT_COOKIE => $cookieValue]);
$headers = json_decode($resp->getBody());
$this->assertEquals($cookieValue, $headers->Cookie);
$server->stop();
}
}