Example #1
0
 /**
  * @covers ::__construct
  * @covers ::getName
  * @covers ::getControllerClass
  * @covers ::getUrlPattern
  * @covers ::getModuleName
  * @covers ::getPrivate
  * @covers ::isPrivate
  * @covers ::getRegExp
  * @covers ::getMethods
  * @covers ::regexpFromUrlPattern
  * @covers ::prepareMethodsInfo
  * @covers ::getControllerMethodForHttpMethod
  */
 public function testInitialization()
 {
     $route = new Route('test_route', TestController::class, '/test/{id:int}', array('GET' => 'index', 'post' => 'save', 'pUt' => 'newItem', 'delete' => false), 'RoutesTesting', false);
     $this->assertEquals('test_route', $route->getName());
     $this->assertEquals(TestController::class, $route->getControllerClass());
     $this->assertEquals('/test/{id:int}', $route->getUrlPattern());
     $this->assertEquals('RoutesTesting', $route->getModuleName());
     $this->assertFalse($route->getPrivate());
     $this->assertFalse($route->isPrivate());
     $regexp = $route->getRegExp();
     $this->assertEquals(1, preg_match($regexp, '/test/1'));
     $this->assertEquals(1, preg_match($regexp, '/test/123'));
     $this->assertEquals(0, preg_match($regexp, '/test/'));
     $this->assertEquals(0, preg_match($regexp, '/test/lipsum'));
     $this->assertEquals(0, preg_match($regexp, '/test/l'));
     $methods = $route->getMethods();
     $this->assertArrayHasKey('get', $methods);
     $this->assertArrayHasKey('post', $methods);
     $this->assertArrayHasKey('put', $methods);
     $this->assertArrayHasKey('delete', $methods);
     foreach ($methods as $method => $info) {
         $this->assertArrayHasKey('method', $info);
         $this->assertArrayHasKey('params', $info);
     }
     $this->assertEquals('index', $route->getControllerMethodForHttpMethod('get'));
     $this->assertEquals('save', $route->getControllerMethodForHttpMethod('POST'));
     $this->assertEquals(false, $route->getControllerMethodForHttpMethod('delete'));
 }