-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from dantleech/mapperpass
Added Mapper pass and expanded config
- Loading branch information
Showing
6 changed files
with
145 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Symfony\Cmf\Bundle\RoutingExtraBundle\DependencyInjection\Compiler; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Reference; | ||
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface; | ||
|
||
/** | ||
* This compiler pass adds additional controller mappers | ||
* to the dynamic router. | ||
* | ||
* @author Daniel Leech <[email protected]> | ||
*/ | ||
class MapperPass implements CompilerPassInterface | ||
{ | ||
public function process(ContainerBuilder $container) | ||
{ | ||
if (!$container->hasDefinition('symfony_cmf_routing_extra.dynamic_router')) { | ||
return; | ||
} | ||
|
||
$router = $container->getDefinition('symfony_cmf_routing_extra.dynamic_router'); | ||
|
||
foreach ($container->findTaggedServiceIds('dynamic_router_controller_mapper') as $id => $attributes) { | ||
$router->addMethodCall('addControllerMapper', array(new Reference($id))); | ||
} | ||
} | ||
} |
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
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
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
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,41 @@ | ||
<?php | ||
|
||
namespace Symfony\Cmf\Bundle\RoutingExtraBundle\Tests\DependencyInjection\Compiler; | ||
|
||
use Symfony\Cmf\Bundle\RoutingExtraBundle\DependencyInjection\Compiler\MapperPass; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Definition; | ||
|
||
class MapperPassTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testMapperPass() | ||
{ | ||
$serviceIds = array( | ||
'test_mapper' => array( | ||
0 => array( | ||
'id' => 'foo_mapper' | ||
) | ||
), | ||
); | ||
|
||
$definition = new Definition('router'); | ||
$builder = $this->getMock('Symfony\Component\DependencyInjection\ContainerBuilder'); | ||
$builder->expects($this->at(0)) | ||
->method('hasDefinition') | ||
->will($this->returnValue(true)); | ||
$builder->expects($this->once()) | ||
->method('findTaggedServiceIds') | ||
->will($this->returnValue($serviceIds)); | ||
$builder->expects($this->once()) | ||
->method('getDefinition') | ||
->with('symfony_cmf_routing_extra.dynamic_router') | ||
->will($this->returnValue($definition)); | ||
|
||
$pass = new MapperPass(); | ||
$pass->process($builder); | ||
$calls = $definition->getMethodCalls(); | ||
$this->assertEquals(1, count($calls)); | ||
$this->assertEquals('addControllerMapper', $calls[0][0]); | ||
} | ||
} | ||
|
62 changes: 62 additions & 0 deletions
62
Tests/DependencyInjection/SymfonyCmfRoutingExtraExtensionTest.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,62 @@ | ||
<?php | ||
|
||
namespace Symfony\Cmf\Bundle\RoutingExtraBundle\Tests\DependencyInjection; | ||
|
||
use Symfony\Cmf\Bundle\RoutingExtraBundle\DependencyInjection\SymfonyCmfRoutingExtraExtension; | ||
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface; | ||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
class SymfonyCmfRoutingExtraExtensionTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function setUp() | ||
{ | ||
$this->ext = new SymfonyCmfRoutingExtraExtension; | ||
$this->builder = new ContainerBuilder; | ||
|
||
$paramBag = $this->getMock('Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface'); | ||
} | ||
|
||
public function testLoadDefault() | ||
{ | ||
$config = array( | ||
array( | ||
'dynamic' => array( | ||
), | ||
'use_sonata_admin' => false, | ||
) | ||
); | ||
|
||
$this->ext->load($config, $this->builder); | ||
$this->assertEquals( | ||
'Symfony\Cmf\Bundle\RoutingExtraBundle\Document\RouteRepository', | ||
$this->builder->getParameter('symfony_cmf_routing_extra.route_repository_class') | ||
); | ||
$this->assertEquals( | ||
'Symfony\Cmf\Bundle\RoutingExtraBundle\Document\ContentRepository', | ||
$this->builder->getParameter('symfony_cmf_routing_extra.content_repository_class') | ||
); | ||
} | ||
|
||
public function testLoadPopulated() | ||
{ | ||
$config = array( | ||
array( | ||
'dynamic' => array( | ||
'route_repository_class' => 'TestRouteRepository', | ||
'content_repository_class' => 'TestContentRepository', | ||
), | ||
'use_sonata_admin' => false, | ||
) | ||
); | ||
|
||
$this->ext->load($config, $this->builder); | ||
$this->assertEquals( | ||
'TestRouteRepository', | ||
$this->builder->getParameter('symfony_cmf_routing_extra.route_repository_class') | ||
); | ||
$this->assertEquals( | ||
'TestContentRepository', | ||
$this->builder->getParameter('symfony_cmf_routing_extra.content_repository_class') | ||
); | ||
} | ||
} |