tests/Controller/BaseTestCase.php
/**
     * Process the application given a request method and URI
     *
     * @param string $requestMethod the request method (e.g. GET, POST, etc.)
     * @param string $requestUri the request URI
     * @param array|null $requestData the request data
     * @param array|null $requestHeaders the request headers
     *
     * @return Response
     */
Process the application given a request method and URI
@param string $requestMethod the request method
@param string $requestUri the request URI
@param array|null $requestData the request data
@param array|null $requestHeaders the request headers

@return Response
Process the application given a request method and URI @param string $requestMethod the request method @param string $requestUri the request URI @param array|null $requestData the request data @param array|null $requestHeaders the request headers @return Response
public function runApp(
        string $requestMethod,
        string $requestUri,
        array $requestData = null,
        array $requestHeaders = null
    ): Response {
        $environment = Environment::mock(
            [
                'REQUEST_METHOD'     => $requestMethod,
                'REQUEST_URI'        => $requestUri,
                'HTTP_AUTHORIZATION' => $requestHeaders['Authorization'] ?? null,
            ]
        );
        $factory = new DecoratedServerRequestFactory(new ServerRequestFactory());
        $request = $factory->createServerRequest(
            $requestMethod,
            $requestUri,
            $environment
        );
        if (null !== $requestData) {
            $request = $request->withParsedBody($requestData);
        }
        if (null !== $requestHeaders) {
            foreach ($requestHeaders as $header_name => $value) {
                $request = clone $request->withAddedHeader($header_name, $value);
            }
        }
        $app = (require __DIR__ . '/../../config/bootstrap.php');
        try {
            $response = $app->handle($request);
        } catch (Throwable $exception) {
            die('ERROR: ' . $exception->getMessage());
        }
        return $response;
    }
public function runApp ( string $ requestMethod , string $ requestUri , array $ requestData = null , array $ requestHeaders = null ) : Response { $ environment = Environment :: mock ( [ 'REQUEST_METHOD' => $ requestMethod , 'REQUEST_URI' => $ requestUri , 'HTTP_AUTHORIZATION' => $ requestHeaders [ 'Authorization' ] ?? null , ] ) ; $ factory = new DecoratedServerRequestFactory ( new ServerRequestFactory ( ) ) ; $ request = $ factory -> createServerRequest ( $ requestMethod , $ requestUri , $ environment ) ; if ( null !== $ requestData ) { $ request = $ request -> withParsedBody ( $ requestData ) ; } if ( null !== $ requestHeaders ) { foreach ( $ requestHeaders as $ header_name => $ value ) { $ request = clone $ request -> withAddedHeader ( $ header_name , $ value ) ; } } $ app = ( require __DIR__ . '/../../config/bootstrap.php' ) ; try { $ response = $ app -> handle ( $ request ) ; } catch ( Throwable $ exception ) { die ( 'ERROR: ' . $ exception -> getMessage ( ) ) ; } return $ response ; }
Process the application given a request method and URI
 @param string $requestMethod the request method (e.g.
Process the application given a request method and URI @param string $requestMethod the request method ( e . g .
// Create a mock environment for testing with // Set up a request object based on the environment // Add request data, if it exists // Add request headers, if it exists // Instantiate the application /** @var App $app */ // Process the application // Return the response