/** * Perform request * * @param string $method * @param string $uri * @param array $params * @param array $server * @param string $content * * @throws \Slim\Exception\MethodNotAllowedException * @throws \Slim\Exception\NotFoundException */ public function request($method, $uri, array $params = [], array $server = [], $content = null) { $method = strtoupper($method); switch ($method) { case 'POST': case 'PUT': case 'PATCH': case 'DELETE': $this->server['slim.input'] = http_build_query($params); $query = ''; break; case 'GET': default: $query = http_build_query($params); break; } $server = array_merge($this->server, $server, ['CONTENT_TYPE' => 'application/json', 'REQUEST_URI' => $uri, 'REQUEST_METHOD' => $method, 'QUERY_STRING' => $query]); $env = Http\Environment::mock($server); $request = Http\Request::createFromEnvironment($env); $response = new Http\Response(); // dirty hack to set body of request :( if (!is_null($content)) { \Closure::bind(function ($request) use($content) { $request->bodyParsed = $content; }, null, $request)->__invoke($request); } $response = $this->app->__invoke($request, $response); $this->request = $request; $this->response = $response; }
/** * Setting up database */ protected function setUpDatabase() { /** @var \Doctrine\DBAL\Driver\Connection $db */ $db = $this->app->getContainer()['dbal']; $db->beginTransaction(); $db->exec('DELETE FROM relations'); $db->exec('DELETE FROM organizations'); $db->exec('ALTER TABLE organizations AUTO_INCREMENT = 1'); $db->commit(); }