作者:martynbi
项目:slim3-controlle
protected function dispatch($path, $method = 'GET', $data = array(), $cookies = array())
{
$container = $this->app->getContainer();
// seperate the path from the query string so we can set in the environment
@(list($path, $queryString) = explode('?', $path));
// Prepare a mock environment
$env = Environment::mock(array('REQUEST_URI' => $path, 'REQUEST_METHOD' => $method, 'QUERY_STRING' => is_null($queryString) ? '' : $queryString));
// Prepare request and response objects
$uri = Uri::createFromEnvironment($env);
$headers = Headers::createFromEnvironment($env);
$cookies = $cookies;
$serverParams = $env->all();
$body = new RequestBody();
// create request, and set params
$req = new $container['request']($method, $uri, $headers, $cookies, $serverParams, $body);
if (!empty($data)) {
$req = $req->withParsedBody($data);
}
$res = new $container['response']();
// // Fix for body, but breaks POST params in tests - http://stackoverflow.com/questions/34823328/response-getbody-is-empty-when-testing-slim-3-routes-with-phpunit
// $body = new RequestBody();
// if (!empty($data))
// $body->write(json_encode($data));
//
// // create request, and set params
// $req = new $container['request']($method, $uri, $headers, $cookies, $serverParams, $body);
// $res = new $container['response']();
$this->headers = $headers;
$this->request = $req;
$this->response = call_user_func_array($this->app, array($req, $res));
}
作者:there
项目:slim-test-helper
private function request($method, $path, $data = array(), $optionalHeaders = array())
{
//Make method uppercase
$method = strtoupper($method);
$options = array('REQUEST_METHOD' => $method, 'REQUEST_URI' => $path);
if ($method === 'GET') {
$options['QUERY_STRING'] = http_build_query($data);
} else {
$params = json_encode($data);
}
// Prepare a mock environment
$env = Environment::mock(array_merge($options, $optionalHeaders));
$uri = Uri::createFromEnvironment($env);
$headers = Headers::createFromEnvironment($env);
$cookies = $this->cookies;
$serverParams = $env->all();
$body = new RequestBody();
// Attach JSON request
if (isset($params)) {
$headers->set('Content-Type', 'application/json;charset=utf8');
$body->write($params);
}
$this->request = new Request($method, $uri, $headers, $cookies, $serverParams, $body);
$response = new Response();
// Invoke request
$app = $this->app;
$this->response = $app($this->request, $response);
// Return the application output.
return (string) $this->response->getBody();
}
作者:SharkIn
项目:ss-pane
/**
* @param $method
* @param $path
* @param $body
* @param $options
* @return Request
*/
protected function requestFactory($method, $path, $body = [], $options = [])
{
$uri = Uri::createFromString($path);
$headers = new Headers();
$cookies = [];
$_POST['_METHOD'] = $method;
if (strtolower($method) != 'get' && is_array($body)) {
foreach ($body as $key => $value) {
$_POST[$key] = $value;
}
}
$envMethod = 'POST';
if (strtolower($method) == 'get') {
$envMethod = 'GET';
}
$env = Environment::mock(['REQUEST_URI' => $path, 'REQUEST_METHOD' => $envMethod, 'HTTP_CONTENT_TYPE' => 'multipart/form-data; boundary=---foo']);
$serverParams = $env->all();
$body = $this->buildBody($body);
//echo $body->getContents();
// @todo
// $request = new Request($method, $uri, $headers, $cookies, $serverParams, $body, []);
$request = Request::createFromEnvironment($env);
unset($_POST);
return $request;
}
作者:quickenloans-mc
项目:mcp-pantho
public function testAbsoluteUrlGetsRouteAndAppendsPortWhenNotStandard()
{
$uri = SlimUri::createFromString('http://host:8443/path/page?query=1');
$this->router->shouldReceive('relativePathFor')->with('route.name', ['param1' => '1'], [])->andReturn('/test-route-page');
$url = new URI($this->router);
$actual = $url->absoluteURIFor($uri, 'route.name', ['param1' => '1']);
$this->assertSame('http://host:8443/test-route-page', $actual);
}
作者:aodkrisd
项目:slim-3-framework-ap
public function requestFactory()
{
$uri = Uri::createFromString('https://example.com:443/foo/bar?abc=123');
$headers = new Headers();
$cookies = [];
$serverParams = [];
$body = new Body(fopen('php://temp', 'r+'));
return new Request('GET', $uri, $headers, $cookies, $serverParams, $body);
}
作者:zithe
项目:mem
protected function createRequest($env)
{
$method = $env["REQUEST_METHOD"];
$uri = Uri::createFromEnvironment($env);
$headers = Headers::createFromEnvironment($env);
$cookies = Cookies::parseHeader($headers->get("Cookie", []));
$serverParams = $env->all();
$body = new Body(fopen("php://input", "r"));
return new Request($method, $uri, $headers, $cookies, $serverParams, $body);
}
作者:php-htt
项目:messag
/**
* {@inheritdoc}
*/
public function createUri($uri)
{
if ($uri instanceof UriInterface) {
return $uri;
}
if (is_string($uri)) {
return Uri::createFromString($uri);
}
throw new \InvalidArgumentException('URI must be a string or UriInterface');
}
作者:ChrisBrento
项目:recipe
/**
* @param $method
* @param string $url
*
* @return Request
*/
public function makeRequest($method, $url = '/')
{
$env = Environment::mock();
$uri = Uri::createFromString('http://example.com' . $url);
$headers = Headers::createFromEnvironment($env);
$serverParams = $env->all();
$body = new RequestBody();
$uploadedFiles = UploadedFile::createFromEnvironment($env);
$request = new Request($method, $uri, $headers, [], $serverParams, $body, $uploadedFiles);
return $request;
}
作者:slimphp-ap
项目:slim-jso
public function requestFactory($acceptType = 'application/json')
{
$env = Environment::mock(['HTTP_ACCEPT' => $acceptType]);
$uri = Uri::createFromString('https://example.com:443/foo/bar?abc=123');
$headers = Headers::createFromEnvironment($env);
$serverParams = $env->all();
$body = new RequestBody();
$uploadedFiles = UploadedFile::createFromEnvironment($env);
$request = new Request('GET', $uri, $headers, [], $serverParams, $body, $uploadedFiles);
return $request;
}
作者:davidepastor
项目:slim-confi
/**
* Run before each test.
*/
public function setUp()
{
$uri = Uri::createFromString('https://example.com:443/foo/bar');
$headers = new Headers();
$cookies = [];
$env = Environment::mock();
$serverParams = $env->all();
$body = new Body(fopen('php://temp', 'r+'));
$this->request = new Request('GET', $uri, $headers, $cookies, $serverParams, $body);
$this->response = new Response();
}
作者:zithe
项目:mem
protected function createRequest()
{
$env = (new Environment())->mock(["PATH_INFO" => "/index/hello/", "SCRIPT_NAME" => "/index.php"]);
$method = $env["REQUEST_METHOD"];
$uri = Uri::createFromEnvironment($env);
$headers = Headers::createFromEnvironment($env);
$cookies = Cookies::parseHeader($headers->get("Cookie", []));
$serverParams = $env->all();
$body = new Body(fopen("php://input", "r"));
return new Request($method, $uri, $headers, $cookies, $serverParams, $body);
}
作者:elbajur
项目:ketupa
/**
* Run before each test
*/
public function setUp()
{
$uri = \Slim\Http\Uri::createFromString('https://example.com:443/foo/bar?abc=123');
$headers = new \Slim\Http\Headers();
$cookies = new \Slim\Collection();
$env = \Slim\Http\Environment::mock();
$serverParams = new \Slim\Collection($env->all());
$body = new \Slim\Http\Body(fopen('php://temp', 'r+'));
$this->request = new \Slim\Http\Request('GET', $uri, $headers, $cookies, $serverParams, $body);
$this->response = new \Slim\Http\Response();
}
作者:mrmoney
项目:slim-mvc-skeleto
public function requestFactory($requestUrl)
{
$uri = Uri::createFromString($requestUrl);
$headers = new Headers();
$cookies = [];
$env = Slim\Http\Environment::mock();
$serverParams = $env->all();
$body = new Body(fopen('php://temp', 'r+'));
$request = new Request('GET', $uri, $headers, $cookies, $serverParams, $body);
return $request;
}
作者:gegglet
项目:sessionmiddlewar
public function requestFactory($queryString = '')
{
$env = Environment::mock();
$uri = Uri::createFromString('https://example.com:443/foo/bar' . $queryString);
$headers = Headers::createFromEnvironment($env);
$cookies = ['user' => 'john', 'id' => '123'];
$serverParams = $env->all();
$body = new RequestBody();
$uploadedFiles = UploadedFile::createFromEnvironment($env);
$request = new Request('GET', $uri, $headers, $cookies, $serverParams, $body, $uploadedFiles);
return $request;
}
作者:kanello
项目:slim-ac
private function requestFactory($endpoint)
{
// Request
$uri = Uri::createFromString('https://example.com:443/' . $endpoint);
$headers = new Headers();
$cookies = [];
$serverParams = [];
$body = new Body(fopen('php://temp', 'r+'));
$request = new Request('GET', $uri, $headers, $cookies, $serverParams, $body);
$request = $request->withAttribute('route', new Route(['get'], '/' . $endpoint, 'CallableFunction'));
return $request;
}
作者:gegglet
项目:Collectiv
public function requestFactory($uri = '/')
{
// Prepare request and response objects
$env = Environment::mock(['SCRIPT_NAME' => '/index.php', 'REQUEST_URI' => '/', 'REQUEST_METHOD' => 'GET']);
$uri = Uri::createFromEnvironment($env);
$headers = Headers::createFromEnvironment($env);
$cookies = [];
$serverParams = $env->all();
$body = new Body(fopen('php://temp', 'r+'));
$req = new Request('GET', $uri, $headers, $cookies, $serverParams, $body);
return $req;
}
作者:usf-i
项目:slim-skeleto
public function setRequest($method = 'GET', $uri = '/', $other = [])
{
// Prepare request and response objects
$base = ['SCRIPT_NAME' => '/index.php', 'REQUEST_URI' => $uri, 'REQUEST_METHOD' => $method];
$env = \Slim\Http\Environment::mock(array_merge($base, $other));
$uri = \Slim\Http\Uri::createFromEnvironment($env);
$headers = \Slim\Http\Headers::createFromEnvironment($env);
$cookies = (array) new \Slim\Collection();
$serverParams = (array) new \Slim\Collection($env->all());
$body = new \Slim\Http\Body(fopen('php://temp', 'r+'));
return new \Slim\Http\Request('GET', $uri, $headers, $cookies, $serverParams, $body);
}
作者:DavidePastor
项目:Slim-Validatio
/**
* Setup for the XML POST requests.
*
* @param string $xml The XML to use to mock the body of the request.
*/
public function setUpXmlPost($xml)
{
$uri = Uri::createFromString('https://example.com:443/foo');
$headers = new Headers();
$headers->set('Content-Type', 'application/xml;charset=utf8');
$cookies = [];
$env = Environment::mock(['SCRIPT_NAME' => '/index.php', 'REQUEST_URI' => '/foo', 'REQUEST_METHOD' => 'POST']);
$serverParams = $env->all();
$body = new RequestBody();
$body->write($xml);
$this->request = new Request('POST', $uri, $headers, $cookies, $serverParams, $body);
$this->response = new Response();
}
作者:gegglet
项目:slimgatewa
/**
* @param string $method
* @param string $uri
* @return Request
*/
public function makeRequest($method = 'GET', $uri = '')
{
$env = Environment::mock([]);
$uri = Uri::createFromString($uri);
$headers = Headers::createFromEnvironment($env);
$cookies = [];
$serverParams = $env->all();
$body = new RequestBody();
$uploadedFiles = UploadedFile::createFromEnvironment($env);
$request = new Request($method, $uri, $headers, $cookies, $serverParams, $body, $uploadedFiles);
$request = $request->withHeader("Content-Type", "application/x-www-form-urlencoded");
return $request;
}
作者:asaokame
项目:slim-tuu
/**
* run application with POST method.
* adds C.S.R.F. token if $post is set.
*
* @param string $path
* @param array $post
*/
protected function runPost($path = '', $post = [])
{
if (!empty($post)) {
// add csrf tokens.
$key = 'unit-csrf';
$val = 'unit-csrf-value';
$_SESSION['csrf'][$key] = $val;
$post['csrf_name'] = $key;
$post['csrf_value'] = $val;
}
$uri = Uri::createFromString($this->root_url . $path);
$this->runApp('POST', $uri, $post);
}