/** * @covers Headzoo\Web\Tools\WebServer::start */ public function testStart() { $this->server->setCallback(function (WebRequest $request) { $this->request = $request; return "Hello, World!"; }); $this->server->start(); $this->assertNotNull($this->request); $this->assertEquals("/", $this->request->getPath()); }
/** * Returns the data for the requested file * * @param WebRequest $request The http request * @return string * @throws Exceptions\HttpStatusError */ protected function getFile(WebRequest $request) { $path = realpath($this->dirRoot . DIRECTORY_SEPARATOR . $request->getPath()); if (false === $path) { throw new Exceptions\HttpStatusError("File not found.", 404); } if (is_dir($path)) { $path .= DIRECTORY_SEPARATOR . $this->index; } $contents = null; $info = pathinfo($path); if ($info["extension"] == "php") { ob_start(); /** @noinspection PhpIncludeInspection */ include $path; $contents = ob_get_contents(); ob_end_clean(); } else { $contents = file_get_contents($path); } return $contents; }
/** * @covers Headzoo\Web\Tools\WebRequest::getBody */ public function testGetBody() { $this->assertEquals($this->values["body"], $this->request->getBody()); }