Skip to content

Commit abc7dc2

Browse files
committed
Use Curl::getOpt() instead of reflection
1 parent 96b3d50 commit abc7dc2

File tree

1 file changed

+10
-51
lines changed

1 file changed

+10
-51
lines changed

tests/PHPCurlClass/PHPCurlClassTest.php

Lines changed: 10 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -981,37 +981,22 @@ public function testSetCookieEncodingSpace()
981981
{
982982
$curl = new Curl();
983983
$curl->setCookie('cookie', 'Om nom nom nom');
984-
985-
$reflectionClass = new ReflectionClass('\Curl\Curl');
986-
$reflectionProperty = $reflectionClass->getProperty('options');
987-
$reflectionProperty->setAccessible(true);
988-
$options = $reflectionProperty->getValue($curl);
989-
$this->assertEquals('cookie=Om%20nom%20nom%20nom', $options[CURLOPT_COOKIE]);
984+
$this->assertEquals('cookie=Om%20nom%20nom%20nom', $curl->getOpt(CURLOPT_COOKIE));
990985
}
991986

992987
public function testSetMultipleCookies()
993988
{
994989
$curl = new Curl();
995990
$curl->setCookie('cookie', 'Om nom nom nom');
996991
$curl->setCookie('foo', 'bar');
997-
998-
$reflectionClass = new ReflectionClass('\Curl\Curl');
999-
$reflectionProperty = $reflectionClass->getProperty('options');
1000-
$reflectionProperty->setAccessible(true);
1001-
$options = $reflectionProperty->getValue($curl);
1002-
$this->assertEquals('cookie=Om%20nom%20nom%20nom; foo=bar', $options[CURLOPT_COOKIE]);
992+
$this->assertEquals('cookie=Om%20nom%20nom%20nom; foo=bar', $curl->getOpt(CURLOPT_COOKIE));
1003993
}
1004994

1005995
public function testSetCookieEncodingColon()
1006996
{
1007997
$curl = new Curl();
1008998
$curl->setCookie('JSESSIONID', '0000wd-PcsB3bZ-KzYGAqm_rKlm:17925chrl');
1009-
1010-
$reflectionClass = new ReflectionClass('\Curl\Curl');
1011-
$reflectionProperty = $reflectionClass->getProperty('options');
1012-
$reflectionProperty->setAccessible(true);
1013-
$options = $reflectionProperty->getValue($curl);
1014-
$this->assertEquals('JSESSIONID=0000wd-PcsB3bZ-KzYGAqm_rKlm:17925chrl', $options[CURLOPT_COOKIE]);
999+
$this->assertEquals('JSESSIONID=0000wd-PcsB3bZ-KzYGAqm_rKlm:17925chrl', $curl->getOpt(CURLOPT_COOKIE));
10151000
}
10161001

10171002
public function testSetCookieString()
@@ -1020,12 +1005,7 @@ public function testSetCookieString()
10201005

10211006
$test = new Test();
10221007
$test->curl->setCookieString($cookie_string);
1023-
1024-
$reflectionClass = new ReflectionClass('\Curl\Curl');
1025-
$reflectionProperty = $reflectionClass->getProperty('options');
1026-
$reflectionProperty->setAccessible(true);
1027-
$options = $reflectionProperty->getValue($test->curl);
1028-
$this->assertEquals($cookie_string, $options[CURLOPT_COOKIE]);
1008+
$this->assertEquals($cookie_string, $test->curl->getOpt(CURLOPT_COOKIE));
10291009
$this->assertEquals('fruit=apple&color=red', $test->server('cookie', 'GET'));
10301010
}
10311011

@@ -3005,27 +2985,16 @@ public function testOptionSet()
30052985
$curl = new Curl();
30062986
$success = $curl->setOpt($option, $value);
30072987

3008-
$reflector = new ReflectionObject($curl);
3009-
$property = $reflector->getProperty('options');
3010-
$property->setAccessible(true);
3011-
$options = $property->getValue($curl);
3012-
30132988
$this->assertTrue($success);
3014-
$this->assertTrue(isset($options[$option]));
3015-
$this->assertEquals($value, $options[$option]);
2989+
$this->assertEquals($value, $curl->getOpt($option));
30162990

30172991
// Ensure the option is not stored when curl_setopt() fails. Make curl_setopt() return false and suppress
30182992
// errors. Triggers warning: "curl_setopt(): Curl option contains invalid characters (\0)".
30192993
$curl = new Curl();
30202994
$success = @$curl->setOpt($option, $null);
30212995

3022-
$reflector = new ReflectionObject($curl);
3023-
$property = $reflector->getProperty('options');
3024-
$property->setAccessible(true);
3025-
$options = $property->getValue($curl);
3026-
30272996
$this->assertFalse($success);
3028-
$this->assertFalse(isset($options[$option]));
2997+
$this->assertNull($curl->getOpt($option));
30292998

30302999
// Ensure options following a Curl::setOpt() failure are not set when using Curl::setOpts().
30313000
$options = array(
@@ -3035,13 +3004,8 @@ public function testOptionSet()
30353004
$curl = new Curl();
30363005
$success = @$curl->setOpts($options);
30373006

3038-
$reflector = new ReflectionObject($curl);
3039-
$property = $reflector->getProperty('options');
3040-
$property->setAccessible(true);
3041-
$options = $property->getValue($curl);
3042-
30433007
$this->assertFalse($success);
3044-
$this->assertFalse(isset($options[CURLOPT_COOKIE]));
3008+
$this->assertNull($curl->getOpt(CURLOPT_COOKIE));
30453009

30463010
// Ensure Curl::setOpts() returns true when all options are successfully set.
30473011
$options = array(
@@ -3052,15 +3016,10 @@ public function testOptionSet()
30523016
$curl = new Curl();
30533017
$success = $curl->setOpts($options);
30543018

3055-
$reflector = new ReflectionObject($curl);
3056-
$property = $reflector->getProperty('options');
3057-
$property->setAccessible(true);
3058-
$options = $property->getValue($curl);
3059-
30603019
$this->assertTrue($success);
3061-
$this->assertEquals('a=b', $options[CURLOPT_COOKIE]);
3062-
$this->assertTrue($options[CURLOPT_FOLLOWLOCATION]);
3063-
$this->assertTrue($options[CURLOPT_VERBOSE]);
3020+
$this->assertEquals('a=b', $curl->getOpt(CURLOPT_COOKIE));
3021+
$this->assertTrue($curl->getOpt(CURLOPT_FOLLOWLOCATION));
3022+
$this->assertTrue($curl->getOpt(CURLOPT_VERBOSE));
30643023
}
30653024

30663025
public function testBuildUrlArgSeparator()

0 commit comments

Comments
 (0)