示例#1
0
 /**
  * Make sure we can set an array of string cookies
  *
  */
 public function testSetCookieStringArray()
 {
     $this->client->setUri($this->baseuri . 'testCookies.php');
     $cookies = array('chocolate' => 'chips', 'crumble' => 'apple', 'another' => 'cookie');
     $this->client->setCookies($cookies);
     $res = $this->client->send();
     $this->assertEquals($res->getBody(), serialize($cookies), 'Response body does not contain the expected cookies');
 }
 /**
  *
  * @param string $url
  * @return insatnce of Zend\Http\Client
  */
 protected function getNewResponse($url = NULL)
 {
     $client = new HttpClient();
     /**
      * Incase of 2nd call , use product url
      */
     if ($url != NULL) {
         $client->setUri($url);
     }
     /**
      * check if it is 2nd call then use the header cookies so that we can use the same session to avoid
      */
     /**
      * sending more traffic to the site for the performance point of view
      */
     if (isset($_SESSION['cookiejar']) && $_SESSION['cookiejar'] instanceof \Zend\Http\Cookies) {
         $cookieJar = $_SESSION['cookiejar'];
     } else {
         // set Curl Adapter
         $client->setAdapter('Zend\\Http\\Client\\Adapter\\Curl');
         // $response = $this->getResponse ();
         // keep the conntection alive for multiple calls
         $client->setOptions(array('keepalive' => true));
         // set content-type
         // $httpResponse->getHeaders ()->addHeaderLine ( 'content-type', 'text/html; charset=utf-8' );
         $client->setUri(SELF::GROCCERYURL);
         $result = $client->send();
         $cookieJar = \Zend\Http\Cookies::fromResponse($result, SELF::GROCCERYURL);
         $_SESSION['cookiejar'] = $cookieJar;
         $client->resetParameters();
         return $result;
     }
     $connectionCookies = $cookieJar->getMatchingCookies($client->getUri());
     // set the cookies for the 2nd call
     $client->setCookies($this->getConntetionCookies($connectionCookies));
     $response = $client->send();
     return $response;
 }