$route->
setDefault('foo', 'bar'
);
$this->
assertEquals('bar',
$route->
getDefault('foo'
), '->setDefault() sets a default value'
);
$route->
setDefault('foo2', 'bar2'
);
$this->
assertEquals('bar2',
$route->
getDefault('foo2'
), '->getDefault() return the default value'
);
$this->
assertNull($route->
getDefault('not_defined'
), '->getDefault() return null if default value is not set'
);
$route->
setDefault('_controller',
$closure =
fn () => 'Hello'
);
$this->
assertEquals($closure,
$route->
getDefault('_controller'
), '->setDefault() sets a default value'
);
$route->
setDefaults(['foo' => 'foo'
]);
$route->
addDefaults(['bar' => 'bar'
]);
$this->
assertEquals($route,
$route->
addDefaults([]), '->addDefaults() implements a fluent interface'
);
$this->
assertEquals(['foo' => 'foo', 'bar' => 'bar'
],
$route->
getDefaults(), '->addDefaults() keep previous defaults'
);
} public function testRequirements() { $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'
);