src/Requester.php
private function request($inRequestMethod, $inRequestUri, $inQueryString='', $inRequestBody=null) {
        ob_start();

        // Configure the Slim application so that it will use the test environment.
        // See the method \Slim\DefaultServicesProvider::register.
        // $this->__applicationConfiguration['environment'] = $environment;
        // $app = new \Slim\App($this->__application);
        // $container = $app->getContainer();

        $container = $this->__application->getContainer();
        $container['environment'] = Environment::mock(array_merge(array(
            'REQUEST_METHOD' => $inRequestMethod,
            'REQUEST_URI'    => $inRequestUri,
            'QUERY_STRING'   => $inQueryString
        ), $this->__serverCgiEnvironmentVariables));

        // Add middleware, if necessary.

        if (! is_null($inRequestBody)) {
            $this->__application->add(function (Request $request, Response $response, $next) use($inRequestBody) {

                // Set the body.
                $fp = fopen("php://temp", 'r+');
                fwrite($fp, $inRequestBody);
                rewind($fp);
                $body = new \Slim\Http\Body($fp);

                // Please note:
                // \Slim\Http\Message::withBody returns a clone of the request.
                $request = $request->withBody($body);
                $response = $next($request, $response);
                return $response;
            });
        }

        if (count($this->__httpHeaders) > 0) {
            $headers = $this->__httpHeaders;
            $this->__application->add(function (Request $request, Response $response, $next) use($headers) {

                foreach ($headers as $_name => $_value) {
                    // Please note:
                    // \Slim\Http\Message::withHeader returns a clone of the request.
                    $request = $request->withHeader($_name, $_value);
                }

                $response = $next($request, $response);
                return $response;
            });
        }

        // Run the Slim application.
        $this->__application->run();

        // Store the request and the response for later use in the unit tests.
        $this->__request = $this->__application->getContainer()->get('request');
        $this->__response = $this->__application->getContainer()->get('response');

        $this->__stdout = ob_get_clean();
        return $this->__stdout;
    }
private function request($inRequestMethod, $inRequestUri, $inQueryString='', $inRequestBody=null) {
        ob_start();

        // Configure the Slim application so that it will use the test environment.
        // See the method \Slim\DefaultServicesProvider::register.
        // $this->__applicationConfiguration['environment'] = $environment;
        // $app = new \Slim\App($this->__application);
        // $container = $app->getContainer();

        $container = $this->__application->getContainer();
        $container['environment'] = Environment::mock(array_merge(array(
            'REQUEST_METHOD' => $inRequestMethod,
            'REQUEST_URI'    => $inRequestUri,
            'QUERY_STRING'   => $inQueryString
        ), $this->__serverCgiEnvironmentVariables));

        // Add middleware, if necessary.

        if (! is_null($inRequestBody)) {
            $this->__application->add(function (Request $request, Response $response, $next) use($inRequestBody) {

                // Set the body.
                $fp = fopen("php://temp", 'r+');
                fwrite($fp, $inRequestBody);
                rewind($fp);
                $body = new \Slim\Http\Body($fp);

                // Please note:
                // \Slim\Http\Message::withBody returns a clone of the request.
                $request = $request->withBody($body);
                $response = $next($request, $response);
                return $response;
            });
        }

        if (count($this->__httpHeaders) > 0) {
            $headers = $this->__httpHeaders;
            $this->__application->add(function (Request $request, Response $response, $next) use($headers) {

                foreach ($headers as $_name => $_value) {
                    // Please note:
                    // \Slim\Http\Message::withHeader returns a clone of the request.
                    $request = $request->withHeader($_name, $_value);
                }

                $response = $next($request, $response);
                return $response;
            });
        }

        // Run the Slim application.
        $this->__application->run();

        // Store the request and the response for later use in the unit tests.
        $this->__request = $this->__application->getContainer()->get('request');
        $this->__response = $this->__application->getContainer()->get('response');

        $this->__stdout = ob_get_clean();
        return $this->__stdout;
    }
Execute a request and return what should have been returned through the standard output.
Let's consider a GET HTTP request to the following URL: http://www.google.com/search?req=a&option=2
- The request method is "GET" (parameter $inRequestMethod).
- The request URI is "/hello/toto" (parameter $inRequestUri).
- The query string is "a=1&b=2$c=3" (parameter $inQueryString).
- There is no request body.

@param string $inRequestMethod HTTP Method to use ('GET', 'POST'...).
@param string $inRequestUri The request URI (example: "/hello/toto").
@param string $inQueryString The query string (example: "a=1&b=2$c=3").
@param string $inRequestBody Request's body to set (for the method POST, typically).
@return string The content of the standard output.
@throws \Exception
@see \Slim\DefaultServicesProvider::register Here you see how the environment is used.
@see \Slim\App::run Here, you can print the request's data (from a real request).
@see \Slim\Http\Environment
@note Please keep in mind that:
- HTTP headers can be configured through the method SoftRequester::setHttpHeaders().
- Server CGI environment variables can be configured through the method SoftRequester::setServerCgiEnvironmentVariables().
@see Requester::setHttpHeaders()
@see Requester::setServerCgiEnvironmentVariables()