Skip to content

Commit

Permalink
Add parameters and compiler passes to container
Browse files Browse the repository at this point in the history
  • Loading branch information
Florian Eckerstorfer committed Jun 5, 2015
1 parent 5ca3c67 commit 14ce7d1
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
18 changes: 16 additions & 2 deletions src/Pli.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Symfony\Component\Config\Definition\ConfigurationInterface;
use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Console\Application;
use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
use Symfony\Component\DependencyInjection\ContainerAwareInterface;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\Yaml\Yaml;
Expand Down Expand Up @@ -68,16 +69,29 @@ public function loadConfiguration(ConfigurationInterface $configuration, array $
/**
* @param ExtensionInterface|null $extension
* @param array $config
* @param array $parameters
* @param CompilerPassInterface $compilerPasses
*
* @return ContainerBuilder
*/
public function buildContainer(ExtensionInterface $extension = null, array $config = [])
{
public function buildContainer(
ExtensionInterface $extension = null,
array $config = [],
array $parameters = [],
array $compilerPasses = []
) {
$container = new ContainerBuilder();
if ($extension !== null) {
$extension->setConfigDirectories($this->configDirectories);
$extension->buildContainer($container, $config);
}
foreach ($parameters as $key => $value) {
$container->setParameter($key, $value);
}
foreach ($compilerPasses as $compilerPass) {
$container->addCompilerPass($compilerPass);
}
$container->compile();

return $container;
}
Expand Down
15 changes: 12 additions & 3 deletions tests/PliTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ public function loadConfigurationShouldLoadConfiguration()
public function loadConfigurationShouldLoadNotConfigurationIfFileDoesNotExist()
{
$rootNode = m::mock('Symfony\Component\Config\Definition\NodeInterface');
// $rootNode->shouldReceive('normalize')->once();
// $rootNode->shouldReceive('merge')->once();
$rootNode->shouldReceive('finalize')->once()->andReturn([]);

$treeBuilder = m::mock('Symfony\Component\Config\Definition\Builder\TreeBuilder');
Expand All @@ -95,9 +93,20 @@ public function buildContainerShouldCreateContainerAndInvokeExtension()
$extension->shouldReceive('setConfigDirectories')->with([vfsStream::url('config')])->once();
$extension->shouldReceive('buildContainer')->once();

$container = $this->pli->buildContainer($extension, ['foo' => 'bar']);
/** @var \Mockery\MockInterface $pass */
$pass = m::mock('Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface');
$pass->shouldReceive('process')->once();

$container = $this->pli->buildContainer(
$extension,
['foo' => 'bar'],
['%DIR%' => 'foobar'],
[$pass]
);

$this->assertInstanceOf('Symfony\Component\DependencyInjection\ContainerBuilder', $container);
$this->assertEquals('foobar', $container->getParameter('%DIR%'));
$this->assertCount(16, $container->getCompiler()->getPassConfig()->getPasses());
}

/**
Expand Down

0 comments on commit 14ce7d1

Please sign in to comment.