Example #1
0
 /**
  * Adds a Request
  *
  * @param \pahanini\curl\Request $request
  * @throws \yii\base\InvalidParamException
  */
 public function add(Request $request)
 {
     if ($request->isExecuted()) {
         throw new InvalidParamException("Can not add executed request");
     }
     $this->_requests[] = $request;
 }
Example #2
0
 public function testResponse()
 {
     $request = new Request(['url' => 'http://httpbin.org/user-agent', 'options' => [CURLOPT_USERAGENT => 'Tester']]);
     $response = $request->execute()->getResponse();
     $content = json_decode($response->content, true);
     $this->assertTrue($request->isExecuted());
     $this->assertNull($request->getErrorMessage());
     $this->assertTrue($request->isSuccessful());
     $this->assertEquals('application/json', $response->getHeader('Content-Type'));
     $this->assertEquals(200, $response->getStatusCode());
     $this->assertEquals('Tester', $content['user-agent']);
 }