public function testRequestMethodPut() { $request = new Request(); $request->setMethod(RequestMethod::PUT); $this->assertTrue($request->isPut()); $this->assertFalse($request->isPost()); }
public function testRegexPattern() { $route = new Route('/dir/(sample|example)(/?)', function () { // ... }); $request = new Request(); $request->setRequestUri('/dir/example/'); $request->setMethod(RequestMethod::GET); $this->assertTrue($route->matches($request)); $request = new Request(); $request->setRequestUri('/dir/example'); $request->setMethod(RequestMethod::GET); $this->assertTrue($route->matches($request)); $request = new Request(); $request->setRequestUri('/dir/sample/'); $request->setMethod(RequestMethod::GET); $this->assertTrue($route->matches($request)); $request = new Request(); $request->setRequestUri('/dir/sample'); $request->setMethod(RequestMethod::GET); $this->assertTrue($route->matches($request)); $request = new Request(); $request->setRequestUri('/dir/samples'); $request->setMethod(RequestMethod::GET); $this->assertFalse($route->matches($request)); }
/** * @runInSeparateProcess */ public function testNotAllowedResponse() { $app = new Enlighten(); $app->get('/sample', function () { echo 'hi!!!'; }); $optionsRequest = new Request(); $optionsRequest->setRequestUri('/sample'); $optionsRequest->setMethod(RequestMethod::POST); $app->setRequest($optionsRequest); $response = $app->start(); $this->assertEquals(ResponseCode::HTTP_METHOD_NOT_ALLOWED, $response->getResponseCode()); }