/**
  * Confirms that cURL options are returned as expected.
  */
 public function testCurlOptions()
 {
     $request = new Request('foo.bar/api', array('composer' => 'brahms'));
     $expected = array(CURLOPT_CUSTOMREQUEST => 'GET', CURLOPT_URL => 'http://foo.bar/api?composer=brahms', CURLOPT_FOLLOWLOCATION => true, CURLOPT_MAXREDIRS => 10);
     $this->assertEquals($expected, $request->getCurlOptions());
     $request->autoRedirect(false);
     unset($expected[CURLOPT_FOLLOWLOCATION]);
     unset($expected[CURLOPT_MAXREDIRS]);
     $this->assertEquals($expected, $request->getCurlOptions());
     $request->setVerb('FROWN');
     $expected[CURLOPT_CUSTOMREQUEST] = 'FROWN';
     $this->assertEquals($expected, $request->getCurlOptions());
     $postContent = 'aosidfjoaisdfjoiasdfj';
     $request->setPayload($postContent);
     $request->setVerb('POST');
     $expected[CURLOPT_CUSTOMREQUEST] = 'POST';
     $expected[CURLOPT_POSTFIELDS] = $postContent;
     // When the payload is a string, the content type should be this
     $expected[CURLOPT_HTTPHEADER] = array('Content-Type: application/x-www-form-urlencoded');
     $this->assertEquals($expected, $request->getCurlOptions());
     // WHen it's an array, it's this
     $postContent = array('foo' => 'bar');
     $request->setPayload($postContent);
     $expected[CURLOPT_HTTPHEADER] = array('Content-Type: multipart/form-data');
     $expected[CURLOPT_POSTFIELDS] = $postContent;
     $request->setBasicAuthentication('max', 'mypassword123');
     $expected[CURLOPT_USERPWD] = 'max:mypassword123';
     $this->assertEquals($expected, $request->getCurlOptions());
     $request->setHeader('Foo: bar');
     $expected[CURLOPT_HTTPHEADER][] = 'Foo: bar';
     $this->assertEquals($expected, $request->getCurlOptions());
 }
 /**
  * Verifies that the appropriate HTTP verb is used in the appropriate
  * situation.
  */
 public function testHTTPVerb()
 {
     $instance = $this->_getStub();
     $instance->callGetResponse(new Request('http://127.0.0.1/'), false);
     $curlOptions = $instance->getCurlOptions();
     $this->assertEquals('GET', $curlOptions[CURLOPT_CUSTOMREQUEST]);
     /* The use of CURLOPT_POST in this framework should be deprecated by
        now, so I'm going to keep the assertions that it not be present in the
        cURL options. */
     $this->assertArrayNotHasKey(CURLOPT_POST, $curlOptions);
     $this->assertEquals((string) $instance->getRequest()->getURL(), 'http://127.0.0.1/');
     // Setting a payload in the request implicitly triggers a POST
     $params = array('foo' => 'bar');
     $request = new Request('http://127.0.0.1/');
     $request->setPayload($params);
     $instance->callGetResponse($request, false);
     $curlOptions = $instance->getCurlOptions();
     $this->assertEquals('POST', $curlOptions[CURLOPT_CUSTOMREQUEST]);
     $this->assertArrayNotHasKey(CURLOPT_POST, $curlOptions);
     $this->assertEquals($params, $curlOptions[CURLOPT_POSTFIELDS]);
     $this->assertEquals('http://127.0.0.1/', (string) $instance->getRequest()->getURL());
     /* Parameters specified in the request constructor shouldn't be used as
        POST parameters even if the verb is set to POST. */
     $request = new Request('http://127.0.0.1/', $params);
     $request->setVerb('POST');
     $instance->callGetResponse($request, false);
     $curlOptions = $instance->getCurlOptions();
     $this->assertEquals('POST', $curlOptions[CURLOPT_CUSTOMREQUEST]);
     $this->assertArrayNotHasKey(CURLOPT_POST, $curlOptions);
     $this->assertArrayNotHasKey(CURLOPT_POSTFIELDS, $curlOptions);
     $this->assertEquals('http://127.0.0.1/?foo=bar', (string) $instance->getRequest()->getURL());
     // Now try a custom verb
     $request = new Request('http://127.0.0.1/', $params);
     $request->setVerb('FROBNICATE');
     $instance->callGetResponse($request, false);
     $curlOptions = $instance->getCurlOptions();
     $this->assertArrayNotHasKey(CURLOPT_POST, $curlOptions);
     $this->assertEquals('FROBNICATE', $curlOptions[CURLOPT_CUSTOMREQUEST]);
     $this->assertEquals('http://127.0.0.1/?foo=bar', (string) $instance->getRequest()->getURL());
 }
 /**
  * Ensures that a verb can be set on the request with setVerb
  *
  * @param string $verb Verb to set
  *
  * @return void
  *
  * @test
  * @dataProvider methodProvider
  */
 public function setVerbAllowsForSettingRequestVerb($verb)
 {
     $request = new \Request($this->config, []);
     $request->setVerb($verb);
     $this->assertEquals($verb, $request->getVerb());
 }