Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FrameworkBundle] added tests for DIC parameters replacements in rout…
…e defaults
- Loading branch information
Showing
2 changed files
with
90 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
src/Symfony/Bundle/FrameworkBundle/Tests/Routing/RouterTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
<?php | ||
|
||
/* | ||
* This file is part of the Symfony framework. | ||
* | ||
* (c) Fabien Potencier <fabien@symfony.com> | ||
* | ||
* This source file is subject to the MIT license that is bundled | ||
* with this source code in the file LICENSE. | ||
*/ | ||
|
||
namespace Symfony\Bundle\FrameworkBundle\Tests\Routing; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Routing\Router; | ||
use Symfony\Component\Routing\Route; | ||
use Symfony\Component\Routing\RouteCollection; | ||
|
||
class RoutingTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testPlaceholders() | ||
{ | ||
$routes = new RouteCollection(); | ||
$routes->add('foo', new Route('/foo', array( | ||
'foo' => '%foo%', | ||
'bar' => '%bar%', | ||
'foobar' => 'foobar', | ||
'foo1' => '%foo', | ||
'foo2' => 'foo%', | ||
'foo3' => 'f%o%o', | ||
))); | ||
|
||
$sc = $this->getServiceContainer($routes); | ||
$sc | ||
->expects($this->at(1)) | ||
->method('hasParameter') | ||
->will($this->returnValue(false)) | ||
; | ||
$sc | ||
->expects($this->at(2)) | ||
->method('hasParameter') | ||
->will($this->returnValue(true)) | ||
; | ||
$sc | ||
->expects($this->at(3)) | ||
->method('getParameter') | ||
->will($this->returnValue('bar')) | ||
; | ||
|
||
$router = new Router($sc, 'foo'); | ||
$route = $router->getRouteCollection()->get('foo'); | ||
|
||
$this->assertEquals('%foo%', $route->getDefault('foo')); | ||
$this->assertEquals('bar', $route->getDefault('bar')); | ||
$this->assertEquals('foobar', $route->getDefault('foobar')); | ||
$this->assertEquals('%foo', $route->getDefault('foo1')); | ||
$this->assertEquals('foo%', $route->getDefault('foo2')); | ||
$this->assertEquals('f%o%o', $route->getDefault('foo3')); | ||
} | ||
|
||
private function getServiceContainer(RouteCollection $routes) | ||
{ | ||
$sc = $this->getMock('Symfony\Component\DependencyInjection\ContainerInterface'); | ||
$sc | ||
->expects($this->once()) | ||
->method('get') | ||
->will($this->returnValue($this->getLoader($routes))) | ||
; | ||
|
||
return $sc; | ||
} | ||
|
||
private function getLoader(RouteCollection $routes) | ||
{ | ||
$loader = $this->getMock('Symfony\Component\Config\Loader\LoaderInterface'); | ||
$loader | ||
->expects($this->any()) | ||
->method('load') | ||
->will($this->returnValue($routes)) | ||
; | ||
|
||
return $loader; | ||
} | ||
} |