public function request($method, $path, $data, $headers = []) { // Capture STDOUT ob_start(); // Prepare a mock environment $options = ['REQUEST_METHOD' => $method, 'SERVER_PORT' => '8000', 'REQUEST_URI' => $path, 'SERVER_NAME' => 'localhost']; foreach ($headers as $key => $value) { $options['HTTP_' . $key] = $value; } $env = Environment::mock($options); $request = TestRequest::createFromEnvironment($env, $data); $container = new \Slim\Container(["environment" => $env, "request" => $request]); // Run the application // this creates an Slim $app $app = new \Slim\App($container); require __DIR__ . '/../app/app.php'; $this->app = $app; $this->request = $app->getContainer()->get("request"); // We fire the routes $this->response = $this->app->run(); // Return STDOUT return ob_get_clean(); }