public function testRules() { $route = new Route('name', 'sourceRoute', 'action'); $this->assertEquals($route->getRules(), []); $route->setRules(['rule1' => '1', 'rule2' => 2]); $this->assertEquals($route->getRules(), ['rule1' => '1', 'rule2' => 2]); $route->addRule('name', 'value'); $this->assertEquals($route->getRules(), ['rule1' => '1', 'rule2' => 2, 'name' => 'value']); $route->removeRule('rule2'); $this->assertEquals($route->getRules(), ['rule1' => '1', 'name' => 'value']); $this->assertEquals($route->getRuleByName('rule1'), '1'); $this->assertEquals($route->getRuleByName('name'), 'value'); $this->assertEquals($route->getRuleByName('unexistent-rule'), null); }
/** * Transforms Route object to PHP array. * @param Route $route Route object to transform. * @return array */ public function transformRouteToArray(Route $route) { return ['name' => $route->getName(), 'action' => $route->getAction(), 'rules' => $route->getRules(), 'methods' => $route->getMethods(), 'route' => $route->getRoute(), 'sourceRoute' => $route->getSourceRoute(), 'defaults' => $route->getDefaults(), 'extras' => $route->getExtras(), 'tokens' => $route->getTokens(), 'arguments' => $route->getArguments()]; }