Permalink
Browse files

Refactor tests, add test case for cores

  • Loading branch information...
1 parent 4ddbac9 commit 40b1d491351a7efdf2d3d298d64b9c9685af8553 @igorw igorw committed May 21, 2012
Showing with 23 additions and 12 deletions.
  1. +2 −2 DependencyInjection/NelmioSolariumExtension.php
  2. +21 −10 Tests/NelmioSolariumExtensionTest.php
View
4 DependencyInjection/NelmioSolariumExtension.php
@@ -39,11 +39,11 @@ public function load(array $configs, ContainerBuilder $container)
}
}
- protected function loadCore($core, $path, ContainerBuilder $container, array $config)
+ protected function loadCore($name, $path, ContainerBuilder $container, array $config)
{
$container
->setDefinition(sprintf('solarium.client.%s', $name), new Definition($config['client']['class']))
- ->setArguments(array($this->createOptionsFromConfig($core, $config)));
+ ->setArguments(array($this->createOptionsFromConfig($name, $config)));
}
protected function createOptionsFromConfig($core, $config)
View
31 Tests/NelmioSolariumExtensionTest.php
@@ -22,10 +22,7 @@ public function testLoadEmptyConfiguration()
{
$config = array();
- $container = $this->createContainer();
- $container->registerExtension(new NelmioSolariumExtension());
- $container->loadFromExtension('nelmio_solarium', $config);
- $this->compileContainer($container);
+ $container = $this->createCompiledContainerForConfig($config);
$this->assertInstanceOf('Solarium_Client', $container->get('solarium.client'));
$this->assertInstanceOf('Solarium_Client_Adapter_Http', $container->get('solarium.client')->getAdapter());
@@ -38,10 +35,7 @@ public function testLoadCustomAdapter()
$config = array('adapter' => array('class' => $adapterClass));
- $container = $this->createContainer();
- $container->registerExtension(new NelmioSolariumExtension());
- $container->loadFromExtension('nelmio_solarium', $config);
- $this->compileContainer($container);
+ $container = $this->createCompiledContainerForConfig($config);
$this->assertInstanceOf('Solarium_Client', $container->get('solarium.client'));
$this->assertInstanceOf($adapterClass, $container->get('solarium.client')->getAdapter());
@@ -51,13 +45,30 @@ public function testLoadCustomClient()
{
$config = array('client' => array('class' => 'Nelmio\SolariumBundle\Tests\StubClient'));
+ $container = $this->createCompiledContainerForConfig($config);
+
+ $this->assertInstanceOf('Nelmio\SolariumBundle\Tests\StubClient', $container->get('solarium.client'));
+ $this->assertInstanceOf('Solarium_Client_Adapter_Http', $container->get('solarium.client')->getAdapter());
+ }
+
+ public function testLoadWithCores()
+ {
+ $config = array('adapter' => array('cores' => array('a' => 'core_a', 'b' => 'core_b')));
+
+ $container = $this->createCompiledContainerForConfig($config);
+
+ $this->assertInstanceOf('Solarium_Client', $container->get('solarium.client.a'));
+ $this->assertInstanceOf('Solarium_Client', $container->get('solarium.client.b'));
+ }
+
+ private function createCompiledContainerForConfig($config)
+ {
$container = $this->createContainer();
$container->registerExtension(new NelmioSolariumExtension());
$container->loadFromExtension('nelmio_solarium', $config);
$this->compileContainer($container);
- $this->assertInstanceOf('Nelmio\SolariumBundle\Tests\StubClient', $container->get('solarium.client'));
- $this->assertInstanceOf('Solarium_Client_Adapter_Http', $container->get('solarium.client')->getAdapter());
+ return $container;
}
private function createContainer()

0 comments on commit 40b1d49

Please sign in to comment.