当前位置: 首页>>代码示例>>PHP>>正文


PHP Curl::setOpts方法代码示例

本文整理汇总了PHP中Curl\Curl::setOpts方法的典型用法代码示例。如果您正苦于以下问题:PHP Curl::setOpts方法的具体用法?PHP Curl::setOpts怎么用?PHP Curl::setOpts使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Curl\Curl的用法示例。


在下文中一共展示了Curl::setOpts方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testOptionSet

 public function testOptionSet()
 {
     // Skip this test on 5.3, 5.4, and HHVM.
     if (version_compare(PHP_VERSION, '5.5.0', '<') || defined('HHVM_VERSION')) {
         $this->markTestSkipped();
     }
     $option = CURLOPT_ENCODING;
     $value = 'gzip';
     $null = chr(0);
     // 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)".
     $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]));
     // Ensure options following a Curl::setOpt() failure are not set when using Curl::setOpts().
     $options = array($option => $null, CURLOPT_COOKIE => 'a=b');
     $curl = new Curl();
     $success = @$curl->setOpts($options);
     $reflector = new ReflectionObject($curl);
     $property = $reflector->getProperty('options');
     $property->setAccessible(true);
     $options = $property->getValue($curl);
     $this->assertFalse($success);
     $this->assertFalse(isset($options[CURLOPT_COOKIE]));
     // Ensure Curl::setOpts() returns true when all options are successfully set.
     $options = array(CURLOPT_COOKIE => 'a=b', CURLOPT_FOLLOWLOCATION => true, CURLOPT_VERBOSE => true);
     $curl = new Curl();
     $success = $curl->setOpts($options);
     $reflector = new ReflectionObject($curl);
     $property = $reflector->getProperty('options');
     $property->setAccessible(true);
     $options = $property->getValue($curl);
     $this->assertTrue($success);
     $this->assertEquals('a=b', $options[CURLOPT_COOKIE]);
     $this->assertTrue($options[CURLOPT_FOLLOWLOCATION]);
     $this->assertTrue($options[CURLOPT_VERBOSE]);
 }
开发者ID:php-curl-class,项目名称:php-curl-class,代码行数:52,代码来源:PHPCurlClassTest.php


注:本文中的Curl\Curl::setOpts方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。