Пример #1
0
 public function testPattern()
 {
     $route = new Route('/:foo');
     $route->setPattern('/:bar');
     $this->assertEquals('/:bar', $route->getPattern(), '->setPattern() sets the pattern');
     $route->setPattern('');
     $this->assertEquals('/', $route->getPattern(), '->setPattern() adds a / at the beginning of the pattern if needed');
     $route->setPattern('bar');
     $this->assertEquals('/bar', $route->getPattern(), '->setPattern() adds a / at the beginning of the pattern if needed');
     $this->assertEquals($route, $route->setPattern(''), '->setPattern() implements a fluent interface');
 }
Пример #2
0
 */
require_once __DIR__ . '/../../../bootstrap.php';
use Symfony\Components\Routing\Route;
$t = new LimeTest(19);
// __construct()
$t->diag('__construct()');
$route = new Route('/:foo', array('foo' => 'bar'), array('foo' => '\\d+'), array('foo' => 'bar'));
$t->is($route->getPattern(), '/:foo', '__construct() takes a pattern as its first argument');
$t->is($route->getDefaults(), array('foo' => 'bar'), '__construct() takes defaults as its second argument');
$t->is($route->getRequirements(), array('foo' => '\\d+'), '__construct() takes requirements as its third argument');
$t->is($route->getOption('foo'), 'bar', '__construct() takes options as its fourth argument');
// ->getPattern() ->setPattern()
$t->diag('->getPattern() ->setPattern()');
$route = new Route('/:foo');
$route->setPattern('/:bar');
$t->is($route->getPattern(), '/:bar', '->setPattern() sets the pattern');
$route->setPattern('');
$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'));