Skip to content

Commit

Permalink
Minior refactoring of configuration handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Koc committed Jan 9, 2016
1 parent 3e302f8 commit c692ec6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 24 deletions.
6 changes: 2 additions & 4 deletions DependencyInjection/SonataAdminExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace Sonata\AdminBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Processor;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ContainerBuilder;
use Symfony\Component\DependencyInjection\Loader\XmlFileLoader;
Expand Down Expand Up @@ -81,9 +80,8 @@ public function load(array $configs, ContainerBuilder $container)
$sidebarMenu->setFactoryMethod('createSidebarMenu');
}

$configuration = new Configuration();
$processor = new Processor();
$config = $processor->processConfiguration($configuration, $configs);
$configuration = $this->getConfiguration($configs, $container);
$config = $this->processConfiguration($configuration, $configs);

$config['options']['javascripts'] = $config['assets']['javascripts'];
$config['options']['stylesheets'] = $config['assets']['stylesheets'];
Expand Down
42 changes: 22 additions & 20 deletions Tests/DependencyInjection/ConfigurationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@ class ConfigurationTest extends \PHPUnit_Framework_TestCase
{
public function testOptions()
{
$processor = new Processor();

$config = $processor->processConfiguration(new Configuration(), array());
$config = $this->process(array());

$this->assertTrue($config['options']['html5_validate']);
$this->assertNull($config['options']['pager_links']);
Expand All @@ -32,9 +30,7 @@ public function testOptionsWithInvalidFormat()
{
$this->setExpectedException('Symfony\Component\Config\Definition\Exception\InvalidTypeException');

$processor = new Processor();

$config = $processor->processConfiguration(new Configuration(), array(array(
$config = $this->process(array(array(
'options' => array(
'html5_validate' => '1',
),
Expand All @@ -43,9 +39,7 @@ public function testOptionsWithInvalidFormat()

public function testCustomTemplatesPerAdmin()
{
$processor = new Processor();

$config = $processor->processConfiguration(new Configuration(), array(array(
$config = $this->process(array(array(
'admin_services' => array(
'my_admin_id' => array(
'templates' => array(
Expand All @@ -62,9 +56,7 @@ public function testCustomTemplatesPerAdmin()

public function testAdminServicesDefault()
{
$processor = new Processor();

$config = $processor->processConfiguration(new Configuration(), array(array(
$config = $this->process(array(array(
'admin_services' => array('my_admin_id' => array()),
)));

Expand Down Expand Up @@ -94,16 +86,14 @@ public function testAdminServicesDefault()

public function testDashboardWithoutRoles()
{
$processor = new Processor();
$config = $processor->processConfiguration(new Configuration(), array());
$config = $this->process(array());

$this->assertEmpty($config['dashboard']['blocks'][0]['roles']);
}

public function testDashboardWithRoles()
{
$processor = new Processor();
$config = $processor->processConfiguration(new Configuration(), array(array(
$config = $this->process(array(array(
'dashboard' => array(
'blocks' => array(array(
'roles' => array('ROLE_ADMIN'),
Expand All @@ -117,8 +107,7 @@ public function testDashboardWithRoles()

public function testDashboardGroups()
{
$processor = new Processor();
$config = $processor->processConfiguration(new Configuration(), array(array(
$config = $this->process(array(array(
'dashboard' => array(
'groups' => array(
'bar' => array(
Expand Down Expand Up @@ -185,8 +174,7 @@ public function testDashboardGroupsWithBadItemsParams()
{
$this->setExpectedException('\InvalidArgumentException', 'Expected either parameters "route" and "label" for array items');

$processor = new Processor();
$config = $processor->processConfiguration(new Configuration(), array(array(
$config = $this->process(array(array(
'dashboard' => array(
'groups' => array(
'bar' => array(
Expand All @@ -204,4 +192,18 @@ public function testDashboardGroupsWithBadItemsParams()
),
)));
}

/**
* Processes an array of configurations and returns a compiled version.
*
* @param array $configs An array of raw configurations
*
* @return array A normalized array
*/
protected function process($configs)
{
$processor = new Processor();

return $processor->processConfiguration(new Configuration(), $configs);
}
}

0 comments on commit c692ec6

Please sign in to comment.