Exemplo n.º 1
0
 /**
  * Test the cookie jar of the response and client
  */
 public function testCookieJar()
 {
     $client = new Client();
     $cookieJar = new Cookie\Jar();
     $client->setCookieJar($cookieJar);
     $this->assertEquals($cookieJar, $client->getCookieJar());
     $request = new Client\Request(array('requestUri' => 'file://' . dirname(__FILE__) . '/_files/client/cookie.txt', 'method' => 'GET'));
     $response = $client->request($request);
     $this->assertInstanceOf('Nimbles\\Http\\Cookie\\Jar', $response->getCookie());
     $responseCookieJar = $response->getCookie()->getArrayCopy();
     $this->assertArrayHasKey('Name', $responseCookieJar);
     $this->assertInstanceOf('Nimbles\\Http\\Cookie', $responseCookieJar['Name']);
     $this->assertEquals('Value', $responseCookieJar['Name']->getValue());
     $this->assertEquals('localhost', $responseCookieJar['Name']->getDomain());
     $this->assertEquals('/', $responseCookieJar['Name']->getPath());
     $this->assertEquals(strtotime('Tue, 31-Dec-2050 23:59:59 GMT') - time(), $responseCookieJar['Name']->getExpires());
     $arrayCookieJar = $cookieJar->getArrayCopy();
     $this->assertArrayHasKey('Name', $arrayCookieJar);
     $this->assertEquals($responseCookieJar['Name'], $arrayCookieJar['Name']);
     $cookieJar->exchangeArray(array());
     //reset the cookie jar
     $client->setAdapter('CurlMulti');
     $request = new Client\Request(array('requestUri' => 'file://' . dirname(__FILE__) . '/_files/client/cookie.txt', 'method' => 'GET'), array('requestUri' => 'file://' . dirname(__FILE__) . '/_files/client/cookie.txt', 'method' => 'GET'));
     $batch = $client->request($request);
     $arrayCookieJar = $cookieJar->getArrayCopy();
     $this->assertArrayHasKey('Name', $arrayCookieJar);
 }