Skip to content

Commit

Permalink
Merge pull request #3 from olerass/master
Browse files Browse the repository at this point in the history
Add support for custom request body
  • Loading branch information
craig-davis committed Nov 10, 2014
2 parents 6655175 + 3bba1f1 commit b216dad
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/There4/Slim/Test/WebTestClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,31 @@ public function __construct(Slim\Slim $slim)
public function __call($method, $arguments)
{
if (in_array($method, $this->testingMethods)) {
list($path, $formVars, $headers) = array_pad($arguments, 3, array());
return $this->request($method, $path, $formVars, $headers);
list($path, $data, $headers) = array_pad($arguments, 3, array());
return $this->request($method, $path, $data, $headers);
}
throw new \BadMethodCallException(strtoupper($method) . ' is not supported');
}

// Abstract way to make a request to SlimPHP, this allows us to mock the
// slim environment
private function request($method, $path, $formVars = array(), $optionalHeaders = array())
private function request($method, $path, $data = array(), $optionalHeaders = array())
{
// Capture STDOUT
ob_start();

$options = array(
'REQUEST_METHOD' => strtoupper($method),
'PATH_INFO' => $path,
'SERVER_NAME' => 'local.dev',
'SERVER_NAME' => 'local.dev'
);

if ($method === 'get') {
$options['QUERY_STRING'] = http_build_query($formVars);
$options['QUERY_STRING'] = http_build_query($data);
} else if (is_array($data)) {
$options['slim.input'] = http_build_query($data);
} else {
$options['slim.input'] = http_build_query($formVars);
$options['slim.input'] = $data;
}

// Prepare a mock environment
Expand Down

0 comments on commit b216dad

Please sign in to comment.