{"action":"opened","issue":{"url":"https://api.github.com/repos/slimphp/Slim/issues/1318","labels_url":"https://api.github.com/repos/slimphp/Slim/issues/1318/labels{/name}","comments_url":"https://api.github.com/repos/slimphp/Slim/issues/1318/comments","events_url":"https://api.github.com/repos/slimphp/Slim/issues/1318/events","html_url":"https://github.com/slimphp/Slim/issues/1318","id":91316131,"number":1318,"title":"[Develop] No way to test App:run","user":{"login":"geggleto","id":4027602,"avatar_url":"https://avatars.githubusercontent.com/u/4027602?v=3","gravatar_id":"","url":"https://api.github.com/users/geggleto","html_url":"https://github.com/geggleto","followers_url":"https://api.github.com/users/geggleto/followers","following_url":"https://api.github.com/users/geggleto/following{/other_user}","gists_url":"https://api.github.com/users/geggleto/gists{/gist_id}","starred_url":"https://api.github.com/users/geggleto/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/geggleto/subscriptions","organizations_url":"https://api.github.com/users/geggleto/orgs","repos_url":"https://api.github.com/users/geggleto/repos","events_url":"https://api.github.com/users/geggleto/events{/privacy}","received_events_url":"https://api.github.com/users/geggleto/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-06-26T17:36:59Z","updated_at":"2015-06-26T17:36:59Z","closed_at":null,"body":"The way the container creates the dependencies make's writing a test case impossible in PHPUnit for the Run method.\r\n\r\nI think the base problem is here...\r\n\r\nContainer.php\r\n```php\r\n//...\r\n        /**\r\n         * This service MUST return a shared instance\r\n         * of \\Slim\\Interfaces\\Http\\EnvironmentInterface.\r\n         *\r\n         * @param Container $c\r\n         *\r\n         * @return EnvironmentInterface\r\n         */\r\n        $this['environment'] = function ($c) {\r\n            return new Environment($_SERVER);\r\n        };\r\n\r\n        /**\r\n         * This service MUST return a NEW instance\r\n         * of \\Psr\\Http\\Message\\ServerRequestInterface.\r\n         */\r\n        $this['request'] = $this->factory(\r\n            /**\r\n             * @param Container $c\r\n             *\r\n             * @return ServerRequestInterface\r\n             */\r\n            function ($c) {\r\n                return Request::createFromEnvironment($c['environment']);\r\n            }\r\n        );\r\n\r\n//...\r\n```\r\n\r\nThen in the App class...\r\n```php\r\n//...\r\n    /**\r\n     * Run application\r\n     *\r\n     * This method traverses the application middleware stack and then sends the\r\n     * resultant Response object to the HTTP client.\r\n     */\r\n    public function run()\r\n    {\r\n        $request = $this->container->get('request');\r\n        $response = $this->container->get('response');\r\n\r\n        // Traverse middleware stack\r\n        try {\r\n            $response = $this->callMiddlewareStack($request, $response);\r\n        } catch (SlimException $e) {\r\n            $response = $e->getResponse();\r\n        } catch (Exception $e) {\r\n            /** @var callable $errorHandler */\r\n            $errorHandler = $this->container->get('errorHandler');\r\n            $response = $errorHandler($request, $response, $e);\r\n        }\r\n\r\n        $this->respond($response);\r\n\r\n        return $response;\r\n    }\r\n//...\r\n}\r\n```\r\n\r\nThere is no way to override the Request class since the Container class is only 1 way.\r\nThe request class is not mergable from a user specified request since the factory method overwrites it.\r\n"}}