Esempio n. 1
0
 public function testCompile()
 {
     $route = new Route('/:foo');
     $this->assertEquals('Symfony\\Components\\Routing\\CompiledRoute', get_class($compiled = $route->compile()), '->compile() returns a compiled route');
     $this->assertEquals($compiled, $route->compile(), '->compile() only compiled the route once');
 }
Esempio n. 2
0
$t->is($route->getPattern(), '/', '->setPattern() adds a / at the beginning of the pattern if needed');
$route->setPattern('bar');
$t->is($route->getPattern(), '/bar', '->setPattern() adds a / at the beginning of the pattern if needed');
$t->is($route->setPattern(''), $route, '->setPattern() implements a fluent interface');
// ->getOptions() ->setOptions()
$t->diag('->getOptions() ->setOptions()');
$route = new Route('/:foo');
$route->setOptions(array('foo' => 'bar'));
$t->is($route->getOptions(), array_merge(array('variable_prefixes' => array(':'), 'segment_separators' => array('/'), 'variable_regex' => '[\\w\\d_]+', 'text_regex' => '.+?', 'compiler_class' => 'Symfony\\Components\\Routing\\RouteCompiler'), array('foo' => 'bar')), '->setOptions() sets the options');
$t->is($route->setOptions(array()), $route, '->setOptions() implements a fluent interface');
// ->getDefaults() ->setDefaults()
$t->diag('->getDefaults() ->setDefaults()');
$route = new Route('/:foo');
$route->setDefaults(array('foo' => 'bar'));
$t->is($route->getDefaults(), array('foo' => 'bar'), '->setDefaults() sets the defaults');
$t->is($route->setDefaults(array()), $route, '->setDefaults() implements a fluent interface');
// ->getRequirements() ->setRequirements() ->getRequirement()
$t->diag('->getRequirements() ->setRequirements() ->getRequirement()');
$route = new Route('/:foo');
$route->setRequirements(array('foo' => '\\d+'));
$t->is($route->getRequirements(), array('foo' => '\\d+'), '->setRequirements() sets the requirements');
$t->is($route->getRequirement('foo'), '\\d+', '->getRequirement() returns a requirement');
$t->is($route->getRequirement('bar'), null, '->getRequirement() returns null if a requirement is not defined');
$route->setRequirements(array('foo' => '^\\d+$'));
$t->is($route->getRequirement('foo'), '\\d+', '->getRequirement() removes ^ and $ from the pattern');
$t->is($route->setRequirements(array()), $route, '->setRequirements() implements a fluent interface');
// ->compile()
$t->diag('->compile()');
$route = new Route('/:foo');
$t->is(get_class($compiled = $route->compile()), 'Symfony\\Components\\Routing\\CompiledRoute', '->compile() returns a compiled route');
$t->is($route->compile(), $compiled, '->compile() only compiled the route once');