clearData(); } protected function req(string $method, string $target): ResponseInterface { $url = "/index.php/apps/news/api".$target; $server = [ 'REQUEST_METHOD' => $method, 'REQUEST_URI' => $url, ]; $req = new ServerRequest($server, [], $url, $method, "php://memory"); $req = $req->withRequestTarget($target); return (new Versions)->dispatch($req); } public function testFetchVersionList() { $exp = new Response(['apiLevels' => ['v1-2']]); $this->assertResponse($exp, $this->req("GET", "/")); $this->assertResponse($exp, $this->req("GET", "/")); $this->assertResponse($exp, $this->req("GET", "/")); } public function testRespondToOptionsRequest() { $exp = new EmptyResponse(204, ['Allow' => "HEAD,GET"]); $this->assertResponse($exp, $this->req("OPTIONS", "/")); } public function testUseIncorrectMethod() { $exp = new EmptyResponse(405, ['Allow' => "HEAD,GET"]); $this->assertResponse($exp, $this->req("POST", "/")); } public function testUseIncorrectPath() { $exp = new EmptyResponse(404); $this->assertResponse($exp, $this->req("GET", "/ook")); $this->assertResponse($exp, $this->req("OPTIONS", "/ook")); } }