From c9c21fd22ecd10eca47120d29314f843846d39af Mon Sep 17 00:00:00 2001 From: PJ Dietz Date: Fri, 25 Jul 2014 23:27:24 -0400 Subject: [PATCH] Test custom cURL options in Client --- test/ClientTest.php | 61 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) diff --git a/test/ClientTest.php b/test/ClientTest.php index 19d9a57..330f8a2 100644 --- a/test/ClientTest.php +++ b/test/ClientTest.php @@ -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(); + } + }