Skip to content

Commit

Permalink
Merge pull request #14 from CircleOfNice/DIBug
Browse files Browse the repository at this point in the history
fixed DI Bug
  • Loading branch information
CircleOfNice committed Mar 22, 2015
2 parents d455f3a + 16871ae commit bd6651d
Show file tree
Hide file tree
Showing 7 changed files with 107 additions and 23 deletions.
10 changes: 5 additions & 5 deletions DependencyInjection/CiRestClientExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,17 @@ class CiRestClientExtension extends Extension
public function load(array $configs, ContainerBuilder $container)
{
$curlConfigFile = __DIR__ . '/../Resources/config/curl_config.yml';
$configs = array_merge($configs, Yaml::parse(file_get_contents($curlConfigFile)));
$configs = array_merge(Yaml::parse(file_get_contents($curlConfigFile)), $configs);
if (!isset($configs['ci_rest_client'])) throw new \RuntimeException('configuration ci_rest_client is missing.');

$configuration = new Configuration();
$config = $this->processConfiguration($configuration, $configs);

if (!isset($config['restclient'])) throw new \RuntimeException('configuration ci.restclient is missing.');
if (!isset($config['restclient']['curl'])) throw new \RuntimeException('configuration ci.restclient.curl is missing.');
if (!isset($config['restclient']['curl']['defaults'])) throw new \RuntimeException('configuration ci.restclient.curl.defaults is missing.');
if (!isset($config['curl'])) throw new \RuntimeException('configuration ci_rest_client.curl is missing.');
if (!isset($config['curl']['defaults'])) throw new \RuntimeException('configuration ci_rest_client.curl.defaults is missing.');

$options = array();
foreach ($config['restclient']['curl']['defaults'] as $key => $value) {
foreach ($config['curl']['defaults'] as $key => $value) {
$options[constant($key)] = $value;
};

Expand Down
14 changes: 4 additions & 10 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,16 @@ class Configuration implements ConfigurationInterface
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('ci');
$rootNode = $treeBuilder->root('ci_rest_client');

$rootNode
->children()
->arrayNode('restclient')
->arrayNode('curl')
->children()
->arrayNode('curl')
->children()
->variableNode('defaults')->end()
->scalarNode('testing_url')->end()
->end()
->end()
->variableNode('defaults')->end()
->end()
->end()
->end()
->end();
->end();

return $treeBuilder;
}
Expand Down
6 changes: 2 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,7 @@ The names and their possible values can be found here: http://php.net/manual/de/
You can change the configuration by adding the following lines to your app/config.yml:

```
ci:
restclient:
ci_rest_client:
curl:
defaults:
$optionName: $value
Expand All @@ -72,8 +71,7 @@ ci:
##Example:

```
ci:
restclient:
ci_rest_client:
curl:
defaults:
CURLOPT_HTTPHEADER: [ 'Content-Type: application/json' ]
Expand Down
3 changes: 1 addition & 2 deletions Resources/config/curl_config.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
ci:
restclient:
ci_rest_client:
curl:
defaults:
CURLOPT_HTTPHEADER: [ 'Content-Type: text/plain' ]
Expand Down
94 changes: 94 additions & 0 deletions Tests/DependencyInjection/ServiceDefinitionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

namespace Ci\RestClientBundle\Tests\DependencyInjection;
use Ci\RestClientBundle\DependencyInjection\CiRestClientExtension;
use Symfony\Component\DependencyInjection\ContainerBuilder;

/**
* Test for the service definitions
*
* @author Tobias Hauck <[email protected]>
* @copyright 2015 TeeAge-Beatz UG
*
* @SuppressWarnings("PHPMD.StaticAccess")
*/
class ServiceDefinitionTest extends \PHPUnit_Framework_TestCase {
/**
* @var CiRestClientExtension
*/
private $extension;

/**
* @var ContainerBuilder
*/
private $container;

/**
* {@inheritdoc}
*/
protected function setUp()
{
$this->extension = new CiRestClientExtension();

$this->container = new ContainerBuilder();
$this->container->registerExtension($this->extension);
}

/**
* Tests the rest client configuration
*
* @test
*
* @covers Ci\RestClientBundle\DependencyInjection\CiRestClientExtension::load
* @covers Ci\RestClientBundle\DependencyInjection\Configuration::getConfigTreeBuilder
*/
public function restClientConfig()
{
$this->loadConfiguration($this->container);
$this->container->compile();

$this->assertTrue($this->container->has('ci.restclient'));
$this->assertInstanceOf('Ci\RestClientBundle\Services\RestClient', $this->container->get('ci.restclient'));
}

/**
* Tests the rest client configuration
*
* @test
*
* @covers Ci\RestClientBundle\DependencyInjection\CiRestClientExtension::load
* @covers Ci\RestClientBundle\DependencyInjection\Configuration::getConfigTreeBuilder
*/
public function configuration()
{
$preConfigs = array(
'ci_rest_client' => array(
'curl' => array(
'defaults' => array(
'CURLOPT_MAXREDIRS' => 30,
)
)
)
);
$this->loadConfiguration($this->container, $preConfigs);
$this->container->compile();

$this->assertTrue($this->container->hasParameter('ci.restclient.curl.defaults'));
$this->assertSame(
$preConfigs['ci_rest_client']['curl']['defaults']['CURLOPT_MAXREDIRS'],
$this->container->getParameter('ci.restclient.curl.defaults')[CURLOPT_MAXREDIRS]
);
}

/**
* Loads the configuration of the extension
*
* @param ContainerBuilder $container
* @param array $existingConfigs
* @return void
*/
private function loadConfiguration(ContainerBuilder $container, array $existingConfigs = array())
{
$this->extension->load($existingConfigs, $container);
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"target-dir" : "Ci/RestClientBundle",
"extra" : {
"branch-alias" : {
"dev-master" : "0.1-dev"
"dev-master" : "0.1.1-dev"
}
}
}
1 change: 0 additions & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
<directory>.</directory>
<exclude>
<directory>Resources</directory>
<directory>DependencyInjection</directory>
<directory>Tests</directory>
<directory>vendor</directory>
<file>Controller/MockController.php</file>
Expand Down

0 comments on commit bd6651d

Please sign in to comment.