Пример #1
0
 /**
  * Test that string payloads with no content type have a default content-type set.
  *
  * @return void
  */
 public function testPostWithStringDataDefaultsToFormEncoding()
 {
     $response = new Response();
     $data = 'some=value&more=data';
     $headers = ['Connection' => 'close', 'User-Agent' => 'CakePHP', 'Content-Type' => 'application/x-www-form-urlencoded'];
     $mock = $this->getMockBuilder('Cake\\Network\\Http\\Adapter\\Stream')->setMethods(['send'])->getMock();
     $mock->expects($this->any())->method('send')->with($this->logicalAnd($this->attributeEqualTo('_body', $data), $this->attributeEqualTo('_headers', $headers)))->will($this->returnValue([$response]));
     $http = new Client(['host' => 'cakephp.org', 'adapter' => $mock]);
     $http->post('/projects/add', $data);
     $http->put('/projects/add', $data);
     $http->delete('/projects/add', $data);
 }
Пример #2
0
 /**
  *  delete Request
  *
  *  Execute delete request
  *
  * @param string  $url - url of the to send the request.
  * @param Array  $data - Array to data to send if not null.
  * @param string  $type - Type of data specified in request.
  * @param Array  $option -  Array of options to add into request as get variables.
  * @param Array  $header -  Array of header to add into request as http headers.
  * @param boolean  $entityAdmin -  flag to use either _api or _admin in request.
  *
  *
  * @return array $response - The response array.
  */
 public function delete($url, $data = NULL, $type = NULL, $option = NULL, $header = NULL, $entityAdmin = false)
 {
     $entity = self::ENTRY_API;
     if ($entityAdmin) {
         $entity = self::ENTRY_ADMIN;
     }
     $uri = $this->protocol . '://' . $this->user . ':' . $this->pass . '@' . $this->host . ':' . $this->port . '/' . self::ENTRY_DB . '/' . $this->db . '/' . $entity . '/' . $url;
     if ($option != NULL) {
         $uri .= '?';
         foreach ($option as $key => $value) {
             # code...
             $uri .= $key . '=' . $value . '&';
         }
     }
     $http = new Client();
     $response = $http->delete($uri, json_encode($data), ['headers' => $header]);
     return $response;
 }