public function setUp()
 {
     $this->client = $this->getSimpleMock('Guzzle\\Http\\ClientInterface');
     $this->facade = new RequestCollectionFacade($this->client);
     $this->request = new Request('GET', '/_request/last');
     $this->request->setClient($this->client);
 }
 public function testHandles404RevalidationResponses()
 {
     $request = new Request('GET', 'http://foo.com');
     $request->setClient(new Client());
     $badResponse = new Response(404, array(), 'Oh no!');
     $badRequest = clone $request;
     $badRequest->setResponse($badResponse, true);
     $response = new Response(200, array(), 'foo');
     $plugin = new CachePlugin();
     $c = new ArrayCache();
     $c->save('foo', array(200, array(), 'foo'));
     $s = new DefaultCacheStorage(new DoctrineCacheAdapter($c));
     $k = new CallbackCacheKeyProvider(function () {
         return 'foo';
     });
     $rev = $this->getMockBuilder('Guzzle\\Plugin\\Cache\\DefaultRevalidation')->setConstructorArgs(array($k, $s, $plugin))->setMethods(array('createRevalidationRequest'))->getMock();
     $rev->expects($this->once())->method('createRevalidationRequest')->will($this->returnValue($badRequest));
     try {
         $rev->revalidate($request, $response);
         $this->fail('Should have thrown an exception');
     } catch (BadResponseException $e) {
         $this->assertSame($badResponse, $e->getResponse());
         $this->assertFalse($c->fetch('foo'));
     }
 }
Example #3
0
 public function testCreatesPreSignedUrlWithXAmzHeaders()
 {
     $signature = new S3Signature();
     $request = new Request('GET', 'https://s3.amazonaws.com', array('X-Amz-Acl' => 'public-read'));
     $c = $this->getServiceBuilder()->get('s3');
     $request->setClient($c);
     $this->assertContains('x-amz-acl:public-read', $signature->createCanonicalizedString($request, time()));
     $this->assertContains('&x-amz-acl=public-read', $signature->createPresignedUrl($request, $c->getCredentials(), time()));
 }
 /**
  * @covers Guzzle\Http\Plugin\CookiePlugin
  */
 public function testAddsCookiesToRequests()
 {
     ArrayCookieJarTest::addCookies($this->storage);
     $this->storage->save(array('domain' => '.y.example.com', 'path' => '/acme/', 'cookie' => array('secure', 'sec'), 'expires' => Guzzle::getHttpDate('+1 day'), 'secure' => true));
     // Add a cookie that is only set on a specific port, so it wont be
     // added to the following requests
     $this->storage->save(array('domain' => '.y.example.com', 'path' => '/acme/', 'cookie' => array('test', 'port'), 'expires' => Guzzle::getHttpDate('+1 day'), 'secure' => false, 'port' => array(8192)));
     $request1 = new Request('GET', 'https://a.y.example.com/acme/');
     $request1->setClient(new Client());
     $request2 = new Request('GET', 'https://a.y.example.com/acme/');
     $request2->setClient(new Client());
     $request3 = new Request('GET', 'http://a.y.example.com/acme/');
     $request3->setClient(new Client());
     $request4 = new Request('GET', 'http://a.y.example.com/acme/');
     $request4->setClient(new Client());
     $request1->getEventDispatcher()->addSubscriber($this->plugin);
     $request2->getEventDispatcher()->addSubscriber($this->plugin);
     $request3->getEventDispatcher()->addSubscriber($this->plugin);
     $request4->getEventDispatcher()->addSubscriber($this->plugin);
     // Set a secure cookie
     $response1 = Response::fromMessage("HTTP/1.1 200 OK\r\nSet-Cookie: a=b; c=d; Max-Age=86400; domain=.example.com; secure;\r\n\r\n");
     // Set a regular cookie
     $response2 = Response::fromMessage("HTTP/1.1 200 OK\r\nSet-Cookie: e=f h; discard; domain=.example.com;\r\n\r\n");
     $response3 = Response::fromMessage("HTTP/1.1 200 OK\r\n\r\n");
     $request1->setResponse($response1, true);
     $request2->setResponse($response2, true);
     $request3->setResponse($response3, true);
     $request1->send();
     $request2->send();
     $request3->send();
     $this->assertEquals('muppet=cookie_monster;secure=sec', (string) $request1->getCookie());
     $this->assertEquals('muppet=cookie_monster;secure=sec;a=b;c=d', (string) $request2->getCookie());
     $this->assertEquals('muppet=cookie_monster;e=f h', (string) $request3->getCookie());
     // Clear the e=f h temporary cookie
     $this->plugin->clearTemporaryCookies();
     $request4->setResponse($response3, true);
     $request4->send();
     $this->assertEquals('muppet=cookie_monster', (string) $request4->getCookie());
 }
Example #5
0
 /**
  * @covers Guzzle\Http\Message\Request::getResponse
  * @covers Guzzle\Http\Message\Request::processResponse
  * @covers Guzzle\Http\Message\Request::getResponseBody
  */
 public function testRequestThrowsExceptionOnBadResponse()
 {
     $response = new Response(404, array('Content-Length' => 3), 'abc');
     $request = new Request('GET', 'http://www.google.com/');
     $request->setClient($this->client);
     try {
         $request->setResponse($response, true);
         $request->send();
         $this->fail('Expected exception not thrown');
     } catch (BadResponseException $e) {
         $this->assertInstanceOf('Guzzle\\Http\\Message\\RequestInterface', $e->getRequest());
         $this->assertInstanceOf('Guzzle\\Http\\Message\\Response', $e->getResponse());
         $this->assertContains('Client error response', $e->getMessage());
     }
 }
Example #6
0
 /**
  * @covers Guzzle\Http\Message\Request::getClient
  * @covers Guzzle\Http\Message\Request::setClient
  */
 public function testRequestsManageClients()
 {
     $request = new Request('GET', 'http://test.com');
     $this->assertNull($request->getClient());
     $request->setClient($this->client);
     $this->assertSame($this->client, $request->getClient());
 }