$route =
new Route('/{foo}'
);
$route->
setRequirements(['foo' => '\d+'
]);
$this->
assertEquals(['foo' => '\d+'
],
$route->
getRequirements(), '->setRequirements() sets the requirements'
);
$this->
assertEquals('\d+',
$route->
getRequirement('foo'
), '->getRequirement() returns a requirement'
);
$this->
assertNull($route->
getRequirement('bar'
), '->getRequirement() returns null if a requirement is not defined'
);
$route->
setRequirements(['foo' => '^\d+$'
]);
$this->
assertEquals('\d+',
$route->
getRequirement('foo'
), '->getRequirement() removes ^ and $ from the path'
);
$this->
assertEquals($route,
$route->
setRequirements([]), '->setRequirements() implements a fluent interface'
);
$route->
setRequirements(['foo' => '\d+'
]);
$route->
addRequirements(['bar' => '\d+'
]);
$this->
assertEquals($route,
$route->
addRequirements([]), '->addRequirements() implements a fluent interface'
);
$this->
assertEquals(['foo' => '\d+', 'bar' => '\d+'
],
$route->
getRequirements(), '->addRequirement() keep previous requirements'
);
} public function testRequirement() { $route =
new Route('/{foo}'
);
$this->
assertFalse($route->
hasRequirement('foo'
), '->hasRequirement() return false if requirement is not set'
);
$route->
setRequirement('foo', '^\d+$'
);
$this->
assertEquals('\d+',
$route->
getRequirement('foo'
), '->setRequirement() removes ^ and $ from the path'
);
$this->
assertTrue($route->
hasRequirement('foo'
), '->hasRequirement() return true if requirement is set'
);
}