class ProviderBasedGeneratorTest in Zircon Profile 8
Same name and namespace in other branches
- 8.0 vendor/symfony-cmf/routing/Tests/Routing/ProviderBasedGeneratorTest.php \Symfony\Cmf\Component\Routing\Tests\Routing\ProviderBasedGeneratorTest
Hierarchy
- class \Symfony\Cmf\Component\Routing\Test\CmfUnitTestCase extends \Symfony\Cmf\Component\Routing\Test\PHPUnit_Framework_TestCase
- class \Symfony\Cmf\Component\Routing\Tests\Routing\ProviderBasedGeneratorTest
Expanded class hierarchy of ProviderBasedGeneratorTest
File
- vendor/
symfony-cmf/ routing/ Tests/ Routing/ ProviderBasedGeneratorTest.php, line 21
Namespace
Symfony\Cmf\Component\Routing\Tests\RoutingView source
class ProviderBasedGeneratorTest extends CmfUnitTestCase {
protected $routeDocument;
protected $routeCompiled;
protected $provider;
/** @var ProviderBasedGenerator */
protected $generator;
protected $context;
public function setUp() {
$this->routeDocument = $this
->buildMock('Symfony\\Component\\Routing\\Route', array(
'getDefaults',
'compile',
));
$this->routeCompiled = $this
->buildMock('Symfony\\Component\\Routing\\CompiledRoute');
$this->provider = $this
->buildMock('Symfony\\Cmf\\Component\\Routing\\RouteProviderInterface');
$this->context = $this
->buildMock('Symfony\\Component\\Routing\\RequestContext');
$this->generator = new TestableProviderBasedGenerator($this->provider);
}
public function testGenerateFromName() {
$name = 'foo/bar';
$this->provider
->expects($this
->once())
->method('getRouteByName')
->with($name)
->will($this
->returnValue($this->routeDocument));
$this->routeDocument
->expects($this
->once())
->method('compile')
->will($this
->returnValue($this->routeCompiled));
$this
->assertEquals('result_url', $this->generator
->generate($name));
}
/**
* @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException
*/
public function testGenerateNotFound() {
$name = 'foo/bar';
$this->provider
->expects($this
->once())
->method('getRouteByName')
->with($name)
->will($this
->returnValue(null));
$this->generator
->generate($name);
}
public function testGenerateFromRoute() {
$this->provider
->expects($this
->never())
->method('getRouteByName');
$this->routeDocument
->expects($this
->once())
->method('compile')
->will($this
->returnValue($this->routeCompiled));
$this
->assertEquals('result_url', $this->generator
->generate($this->routeDocument));
}
public function testSupports() {
$this
->assertTrue($this->generator
->supports('foo/bar'));
$this
->assertTrue($this->generator
->supports($this->routeDocument));
$this
->assertFalse($this->generator
->supports($this));
}
public function testGetRouteDebugMessage() {
$this
->assertContains('/some/key', $this->generator
->getRouteDebugMessage(new RouteObject()));
$this
->assertContains('/de/test', $this->generator
->getRouteDebugMessage(new Route('/de/test')));
$this
->assertContains('/some/route', $this->generator
->getRouteDebugMessage('/some/route'));
$this
->assertContains('a:1:{s:10:"route_name";s:7:"example";}', $this->generator
->getRouteDebugMessage(array(
'route_name' => 'example',
)));
}
/**
* Tests the generate method with passing in a route object into generate().
*
* @expectedException \Symfony\Component\Routing\Exception\InvalidParameterException
*/
public function testGenerateByRoute() {
$this->generator = new ProviderBasedGenerator($this->provider);
// Setup a route with a numeric parameter, but pass in a string, so it
// fails and getRouteDebugMessage should be triggered.
$route = new Route('/test');
$route
->setPath('/test/{number}');
$route
->setRequirement('number', '\\+d');
$this->generator
->setStrictRequirements(true);
$context = new RequestContext();
$this->generator
->setContext($context);
$this
->assertSame(null, $this->generator
->generate($route, array(
'number' => 'string',
)));
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
CmfUnitTestCase:: |
protected | function | ||
ProviderBasedGeneratorTest:: |
protected | property | ||
ProviderBasedGeneratorTest:: |
protected | property | @var ProviderBasedGenerator | |
ProviderBasedGeneratorTest:: |
protected | property | ||
ProviderBasedGeneratorTest:: |
protected | property | ||
ProviderBasedGeneratorTest:: |
protected | property | ||
ProviderBasedGeneratorTest:: |
public | function | ||
ProviderBasedGeneratorTest:: |
public | function | Tests the generate method with passing in a route object into generate(). | |
ProviderBasedGeneratorTest:: |
public | function | ||
ProviderBasedGeneratorTest:: |
public | function | ||
ProviderBasedGeneratorTest:: |
public | function | @expectedException \Symfony\Component\Routing\Exception\RouteNotFoundException | |
ProviderBasedGeneratorTest:: |
public | function | ||
ProviderBasedGeneratorTest:: |
public | function |