From b1f345b2f3ebe55f5c34b0c80e0804af3f5b330c Mon Sep 17 00:00:00 2001 From: Zach Borboa Date: Sun, 7 Aug 2016 22:24:39 -0700 Subject: [PATCH] Add test for Curl::setOpt --- tests/PHPCurlClass/PHPCurlClassTest.php | 33 +++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tests/PHPCurlClass/PHPCurlClassTest.php b/tests/PHPCurlClass/PHPCurlClassTest.php index 3d7bc84..39967ee 100644 --- a/tests/PHPCurlClass/PHPCurlClassTest.php +++ b/tests/PHPCurlClass/PHPCurlClassTest.php @@ -2754,4 +2754,37 @@ class CurlTest extends PHPUnit_Framework_TestCase $test->server('request_method', 'GET'); $this->assertTrue(is_float($test->curl->totalTime)); } + + public function testOptionSet() + { + $option = CURLOPT_ENCODING; + $value = 'gzip'; + + // Ensure the option is stored when curl_setopt() succeeds. + $curl = new Curl(); + $success = $curl->setOpt($option, $value); + + $reflector = new ReflectionObject($curl); + $property = $reflector->getProperty('options'); + $property->setAccessible(true); + $options = $property->getValue($curl); + + $this->assertTrue($success); + $this->assertTrue(isset($options[$option])); + $this->assertEquals($value, $options[$option]); + + // Ensure the option is not stored when curl_setopt() fails. Make curl_setopt() return false and suppress + // errors. Triggers warning: "curl_setopt(): Curl option contains invalid characters (\0)". + $null = chr(0); + $curl = new Curl(); + $success = @$curl->setOpt($option, $null); + + $reflector = new ReflectionObject($curl); + $property = $reflector->getProperty('options'); + $property->setAccessible(true); + $options = $property->getValue($curl); + + $this->assertFalse($success); + $this->assertFalse(isset($options[$option])); + } }