Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the functionality to configure paths from which fixtures will be …
…loaded
- Loading branch information
Showing
6 changed files
with
130 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
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,40 @@ | ||
<?php | ||
|
||
namespace Doctrine\Bundle\FixturesBundle\DependencyInjection; | ||
|
||
use Symfony\Component\Config\Definition\ConfigurationInterface; | ||
use Symfony\Component\Config\Definition\Builder\TreeBuilder; | ||
use Symfony\Component\Config\Definition\Builder\NodeDefinition; | ||
|
||
/** | ||
* @author Tyler Stroud <tyler@tylerstroud.com> | ||
* | ||
*/ | ||
class Configuration implements ConfigurationInterface | ||
{ | ||
/** | ||
* @return TreeBuilder | ||
*/ | ||
public function getConfigTreeBuilder() | ||
{ | ||
$treeBuilder = new TreeBuilder(); | ||
$rootNode = $treeBuilder->root('doctrine_fixtures', 'array'); | ||
|
||
$this->addPathsConfiguration($rootNode); | ||
|
||
return $treeBuilder; | ||
} | ||
|
||
/** | ||
* @param NodeDefinition $root | ||
*/ | ||
protected function addPathsConfiguration(NodeDefinition $root) | ||
{ | ||
$root | ||
->children() | ||
->arrayNode('paths') | ||
->info('An array of paths to where your fixtures are located.') | ||
->prototype('scalar')->end() | ||
->end(); | ||
} | ||
} |
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,27 @@ | ||
<?php | ||
|
||
namespace Doctrine\Bundle\FixturesBundle\DependencyInjection; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
use Symfony\Component\DependencyInjection\Extension\Extension; | ||
|
||
/** | ||
* @author Tyler Stroud <tyler@tylerstroud.com> | ||
*/ | ||
class DoctrineFixturesExtension extends Extension | ||
{ | ||
/** | ||
* @param array $configs | ||
* @param ContainerBuilder $container | ||
*/ | ||
public function load(array $configs, ContainerBuilder $container) | ||
{ | ||
$configuration = new Configuration(); | ||
$config = $this->processConfiguration($configuration, $configs); | ||
|
||
if (isset($config['paths'])) { | ||
$container->setParameter('doctrine_fixtures.paths', $config['paths']); | ||
} | ||
} | ||
} | ||
|
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
36 changes: 36 additions & 0 deletions
36
Tests/DependencyInjection/DoctrineFixturesExtensionTest.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,36 @@ | ||
<?php | ||
|
||
namespace Doctrine\Bundle\FixturesBundle\DependencyInjection; | ||
|
||
use Symfony\Component\DependencyInjection\ContainerBuilder; | ||
|
||
/** | ||
* @author Tyler Stroud <tyler@tylerstroud.com> | ||
*/ | ||
class DoctrineFixturesExtensionTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
protected $container; | ||
protected $extension; | ||
|
||
public function setUp() | ||
{ | ||
$this->container = new ContainerBuilder(); | ||
$this->extension = new DoctrineFixturesExtension(); | ||
} | ||
|
||
public function testPathsConfiguration() | ||
{ | ||
$config = [ | ||
'doctrine_fixtures' => [ | ||
'paths' => [ | ||
'/path1/', | ||
'/path2/' | ||
] | ||
] | ||
]; | ||
|
||
$this->extension->load($config, $this->container); | ||
$this->assertTrue($this->container->hasParameter('doctrine_fixtures.paths')); | ||
$this->assertEquals(['/path1/', '/path2/'], $this->container->getParameter('doctrine_fixtures.paths')); | ||
} | ||
} |
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,3 @@ | ||
<?php | ||
|
||
require_once __DIR__ . '/../vendor/autoload.php'; |