Created
March 3, 2016 15:41
-
-
Save matthewbaggett/59d958e3a9df8828ce91 to your computer and use it in GitHub Desktop.
Broken request maker.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function request($method, $path, $post = array()) | |
{ | |
// Prepare a mock environment | |
/** | |
* @var \Slim\App $app | |
*/ | |
$app = include APP_ROOT . "/src/Slim.php"; | |
// Prepare request and response objects | |
$env = Environment::mock( | |
[ | |
'SCRIPT_NAME' => '/index.php', | |
'REQUEST_URI' => $path, | |
'REQUEST_METHOD' => $method, | |
] | |
); | |
$uri = Uri::createFromEnvironment($env); | |
$headers = Headers::createFromEnvironment($env); | |
$cookies = []; | |
$serverParams = $env->all(); | |
$body = new RequestBody(); | |
$body->write(json_encode($post)); | |
$body->rewind(); | |
$request = new Request($method, $uri, $headers, $cookies, $serverParams, $body); | |
$request = $request->withBody($body); | |
$response = new Response(); | |
// Invoke app | |
$app($request, $response); | |
return $response; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment