Skip to content

Commit

Permalink
refactored send definitions
Browse files Browse the repository at this point in the history
  • Loading branch information
everzet committed Mar 1, 2012
1 parent 344ceab commit be83077
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion Behat/CommonContexts/WebApiContext.php
Expand Up @@ -102,7 +102,7 @@ public function iSendARequestWithValues($method, $url, TableNode $post)
}

/**
* Sends HTTP request to specific URL with body from PyString.
* Sends HTTP request to specific URL with raw body from PyString.
*
* @param string $method request method
* @param string $url relative url
Expand All @@ -115,6 +115,33 @@ public function iSendARequestWithBody($method, $url, PyStringNode $string)
$url = $this->baseUrl.'/'.ltrim($this->replacePlaceHolder($url), '/');
$string = $this->replacePlaceHolder(trim($string));

switch ($method) {
case 'POST':
$this->browser->call($url, Request::METHOD_POST, array(), $string);
break;
case 'PUT':
$this->browser->call($url, Request::METHOD_PUT, array(), $string);
break;
case 'DELETE':
$this->browser->call($url, Request::METHOD_DELETE, array(), $string);
break;
}
}

/**
* Sends HTTP request to specific URL with form data from PyString.
*
* @param string $method request method
* @param string $url relative url
* @param PyStringNode $string request body
*
* @When /^(?:I )?send a (POST|PUT|DELETE) request to "([^"]+)" with form data:$/
*/
public function iSendARequestWithFormData($method, $url, PyStringNode $string)
{
$url = $this->baseUrl.'/'.ltrim($this->replacePlaceHolder($url), '/');
$string = $this->replacePlaceHolder(trim($string));

parse_str(implode('&', explode("\n", $string)), $fields);

switch ($method) {
Expand Down

0 comments on commit be83077

Please sign in to comment.