Exemple #1
0
 protected function execute($method = 'GET', $url, $parameters = array(), $files = array())
 {
     foreach ($this->headers as $header => $val) {
         $header = str_replace('-', '_', strtoupper($header));
         $this->client->setServerParameter("HTTP_{$header}", $val);
         # Issue #827 - symfony foundation requires 'CONTENT_TYPE' without HTTP_
         if ($this->isFunctional and $header == 'CONTENT_TYPE') {
             $this->client->setServerParameter($header, $val);
         }
     }
     // allow full url to be requested
     $url = (strpos($url, '://') === false ? $this->config['url'] : '') . $url;
     $parameters = $this->encodeApplicationJson($method, $parameters);
     if (is_array($parameters) || $method == 'GET') {
         if (!empty($parameters) && $method == 'GET') {
             $url .= '?' . http_build_query($parameters);
         }
         if ($method == 'GET') {
             $this->debugSection("Request", "{$method} {$url}");
         } else {
             $this->debugSection("Request", "{$method} {$url} " . json_encode($parameters));
         }
         $this->client->request($method, $url, $parameters, $files);
     } else {
         $this->debugSection("Request", "{$method} {$url} " . $parameters);
         $this->client->request($method, $url, array(), $files, array(), $parameters);
     }
     $this->response = $this->client->getInternalResponse()->getContent();
     $this->debugSection("Response", $this->response);
     if (count($this->client->getInternalRequest()->getCookies())) {
         $this->debugSection('Cookies', $this->client->getInternalRequest()->getCookies());
     }
     $this->debugSection("Headers", $this->client->getInternalResponse()->getHeaders());
     $this->debugSection("Status", $this->client->getInternalResponse()->getStatus());
 }
 protected function getRunningClient()
 {
     if ($this->client->getInternalRequest() === null) {
         throw new ModuleException($this, "Response is empty. Use `\$I->sendXXX()` methods to send HTTP request");
     }
     return $this->client;
 }
Exemple #3
0
 protected function execute($method = 'GET', $url, $parameters = [], $files = [])
 {
     $this->debugSection("Request headers", $this->headers);
     foreach ($this->headers as $header => $val) {
         $header = str_replace('-', '_', strtoupper($header));
         $this->client->setServerParameter("HTTP_{$header}", $val);
         // Issue #1650 - Symfony BrowserKit changes HOST header to request URL
         if ($header === 'HOST') {
             $this->client->setServerParameter("HTTP_ HOST", $val);
         }
         // Issue #827 - symfony foundation requires 'CONTENT_TYPE' without HTTP_
         if ($this->isFunctional && $header === 'CONTENT_TYPE') {
             $this->client->setServerParameter($header, $val);
         }
     }
     // allow full url to be requested
     if (strpos($url, '://') === false) {
         $url = $this->config['url'] . $url;
     }
     $this->params = $parameters;
     $parameters = $this->encodeApplicationJson($method, $parameters);
     if (is_array($parameters) || $method === 'GET') {
         if (!empty($parameters) && $method === 'GET') {
             $url .= '?' . http_build_query($parameters);
         }
         if ($method == 'GET') {
             $this->debugSection("Request", "{$method} {$url}");
         } else {
             $this->debugSection("Request", "{$method} {$url} " . json_encode($parameters));
         }
         $this->client->request($method, $url, $parameters, $files);
     } else {
         $requestData = $parameters;
         if (!ctype_print($requestData) && false === mb_detect_encoding($requestData, mb_detect_order(), true)) {
             // if the request data has non-printable bytes and it is not a valid unicode string, reformat the
             // display string to signify the presence of request data
             $requestData = '[binary-data length:' . strlen($requestData) . ' md5:' . md5($requestData) . ']';
         }
         $this->debugSection("Request", "{$method} {$url} " . $requestData);
         $this->client->request($method, $url, [], $files, [], $parameters);
     }
     $this->response = (string) $this->connectionModule->_getResponseContent();
     $this->debugSection("Response", $this->response);
     if (count($this->client->getInternalRequest()->getCookies())) {
         $this->debugSection('Cookies', $this->client->getInternalRequest()->getCookies());
     }
     $this->debugSection("Headers", $this->client->getInternalResponse()->getHeaders());
     $this->debugSection("Status", $this->client->getInternalResponse()->getStatus());
 }
 public function testDoRequest()
 {
     $client = new Client(new TestHttpKernel());
     $client->request('GET', '/');
     $this->assertEquals('Request: /', $client->getResponse()->getContent(), '->doRequest() uses the request handler to make the request');
     $this->assertInstanceOf('Symfony\\Component\\BrowserKit\\Request', $client->getInternalRequest());
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Request', $client->getRequest());
     $this->assertInstanceOf('Symfony\\Component\\BrowserKit\\Response', $client->getInternalResponse());
     $this->assertInstanceOf('Symfony\\Component\\HttpFoundation\\Response', $client->getResponse());
     $client->request('GET', 'http://www.example.com/');
     $this->assertEquals('Request: /', $client->getResponse()->getContent(), '->doRequest() uses the request handler to make the request');
     $this->assertEquals('www.example.com', $client->getRequest()->getHost(), '->doRequest() uses the request handler to make the request');
     $client->request('GET', 'http://www.example.com/?parameter=http://google.com');
     $this->assertEquals('http://www.example.com/?parameter=' . urlencode('http://google.com'), $client->getRequest()->getUri(), '->doRequest() uses the request handler to make the request');
 }
Exemple #5
0
 protected function execute($method = 'GET', $url, $parameters = [], $files = [])
 {
     $this->debugSection("Request headers", $this->headers);
     if ($parameters instanceof \JsonSerializable) {
         $parameters = $parameters->jsonSerialize();
     }
     foreach ($this->headers as $header => $val) {
         $header = str_replace('-', '_', strtoupper($header));
         $this->client->setServerParameter("HTTP_{$header}", $val);
         // Issue #1650 - Symfony BrowserKit changes HOST header to request URL
         if (strtolower($header) == 'host') {
             $this->client->setServerParameter("HTTP_ HOST", $val);
         }
         // Issue #827 - symfony foundation requires 'CONTENT_TYPE' without HTTP_
         if ($this->isFunctional and $header == 'CONTENT_TYPE') {
             $this->client->setServerParameter($header, $val);
         }
     }
     // allow full url to be requested
     $url = (strpos($url, '://') === false ? $this->config['url'] : '') . $url;
     $this->params = $parameters;
     $parameters = $this->encodeApplicationJson($method, $parameters);
     if (is_array($parameters) || $method == 'GET') {
         if (!empty($parameters) && $method == 'GET') {
             $url .= '?' . http_build_query($parameters);
         }
         if ($method == 'GET') {
             $this->debugSection("Request", "{$method} {$url}");
         } else {
             $this->debugSection("Request", "{$method} {$url} " . json_encode($parameters));
         }
         $this->client->request($method, $url, $parameters, $files);
     } else {
         $this->debugSection("Request", "{$method} {$url} " . $parameters);
         $this->client->request($method, $url, [], $files, [], $parameters);
     }
     $this->response = (string) $this->client->getInternalResponse()->getContent();
     $this->debugSection("Response", $this->response);
     if (count($this->client->getInternalRequest()->getCookies())) {
         $this->debugSection('Cookies', $this->client->getInternalRequest()->getCookies());
     }
     $this->debugSection("Headers", $this->client->getInternalResponse()->getHeaders());
     $this->debugSection("Status", $this->client->getInternalResponse()->getStatus());
 }