/**
  * @param string $endpoint
  * @param string $content
  * @param array $headers
  * @param array $files
  * @return Response
  */
 public function send($endpoint, $content, array $headers = array(), array $files = array())
 {
     // Make headers buzz friendly
     array_walk($headers, function (&$value, $key) {
         $value = sprintf('%s: %s', $key, $value);
     });
     if ($files) {
         // HTTP query content
         parse_str($content, $fields);
         // Add files to request
         foreach ($files as $key => $items) {
             $fields[$key] = array();
             foreach ($items as $name => $item) {
                 $item = new FormUpload($item);
                 if (!is_numeric($name)) {
                     $item->setName($name);
                 }
                 $fields[$key] = $item;
             }
         }
         $response = $this->browser->submit($endpoint, $fields, RequestInterface::METHOD_POST, array_values($headers));
     } else {
         // JSON content
         $response = $this->browser->post($endpoint, array_values($headers), $content);
     }
     return new Response($response->getStatusCode(), $response->getContent());
 }
 public function testContentType()
 {
     $upload = new FormUpload(__DIR__ . '/Fixtures/google.png');
     $upload->setName('company[logo]');
     $upload->setContentType('foo/bar');
     $this->assertEquals(array('Content-Disposition: form-data; name="company[logo]"; filename="google.png"', 'Content-Type: foo/bar'), $upload->getHeaders());
 }
Esempio n. 3
0
 /**
  * @Given /^that i want to create "([^"]*)" with name "([^"]*)" and content "([^"]*)" with type "([^"]*)"$/
  */
 public function thatIWantToCreateWithNameAndContentWithType($form, $name, $content, $contentType)
 {
     if ($contentType == 'file') {
         $fileName = $content;
         $content = new FormUpload(__DIR__ . '/assets/' . $fileName);
         $content->setName($fileName);
     }
     if (!array_key_exists($form, $this->fields)) {
         $this->fields[$form] = array();
     }
     $this->fields[$form][$name] = $content;
 }