Skip to content

Commit

Permalink
Merge pull request #4 from shirshir/add-extra-config-options
Browse files Browse the repository at this point in the history
Add verify_ssl and proxy_address bundle options.
  • Loading branch information
ManneW committed Jul 29, 2014
2 parents 2e67633 + b9a7f64 commit a4b121b
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 5 deletions.
8 changes: 8 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@ public function getConfigTreeBuilder()
->scalarNode('auth_token')
->info('HipChat API token')
->end()
->booleanNode('verify_ssl')
->defaultTrue()
->info('Set to false if you do not want to verify SSL certificates')
->end()
->scalarNode('proxy_address')
->defaultNull()
->info('If needed you can specify a proxy that is used when connecting to HipChat.')
->end()
->end();

return $treeBuilder;
Expand Down
8 changes: 8 additions & 0 deletions DependencyInjection/MannewHipchatExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,13 @@ public function load(array $configs, ContainerBuilder $container)
'mannew_hipchat.auth_token',
$config['auth_token']
);
$container->setParameter(
'mannew_hipchat.verify_ssl',
$config['verify_ssl']
);
$container->setParameter(
'mannew_hipchat.proxy_address',
$config['proxy_address']
);
}
}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ Update your config.yml to contain the a section for this bundle.
```yaml
mannew_hipchat:
auth_token: YOUR_HIPCHAT_AUTH_TOKEN_HERE
verify_ssl: true # optional
proxy_address: ~ # optional
```

## Usage
Expand Down
6 changes: 6 additions & 0 deletions Resources/config/hipchat.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@
<services>
<service id="hipchat" class="HipChat\HipChat">
<argument>%mannew_hipchat.auth_token%</argument>
<call method="set_verify_ssl">
<argument>%mannew_hipchat.verify_ssl%</argument>
</call>
<call method="set_proxy">
<argument>%mannew_hipchat.proxy_address%</argument>
</call>
</service>
</services>
</container>
79 changes: 74 additions & 5 deletions Tests/DependencyInjection/MannewHipchatExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,19 @@ class MannewHipchatExtensionTest extends \PHPUnit_Framework_TestCase
public function testLoadConfigThrowsExceptionOnMissingAuthToken()
{
$config = array();
$this->extension->load(array($config), $container = $this->getContainer());
$this->extension->load(array($config), $container = $this->getEmptyTestContainer());
}

public function testHipChatServiceIsDefined()
{
$config = array(
'auth_token' => uniqid()
);
$container = $this->getEmptyTestContainer();
$this->loadConfigIntoContainer($config, $container);
$containerHasDefinitionForHipchatService = $container->hasDefinition('hipchat');

$this->assertTrue($containerHasDefinitionForHipchatService);
}

public function testLoadConfigWithAuthToken()
Expand All @@ -27,10 +39,58 @@ public function testLoadConfigWithAuthToken()
$config = array(
'auth_token' => $testToken
);
$this->extension->load(array($config), $container = $this->getContainer());
$container = $this->getEmptyTestContainer();
$this->loadConfigIntoContainer($config, $container);

$this->assertContainerParameterEquals($container, 'auth_token', $testToken);
}

public function testLoadConfigWithVerifySSLOption()
{
$verifySSL = false;
$config = array(
'verify_ssl' => $verifySSL,
'auth_token' => uniqid(),
);
$container = $this->getEmptyTestContainer();
$this->loadConfigIntoContainer($config, $container);

$this->assertContainerParameterEquals($container, 'verify_ssl', $verifySSL);
}

public function testLoadConfigWithProxyAddressOption()
{
$proxyAddress = 'http://127.0.0.1:8888';
$config = array(
'proxy_address' => $proxyAddress,
'auth_token' => uniqid(),
);
$container = $this->getEmptyTestContainer();
$this->loadConfigIntoContainer($config, $container);

$this->assertEquals($testToken, $container->getParameter('mannew_hipchat.auth_token'));
$this->assertTrue($container->hasDefinition('hipchat'));
$this->assertContainerParameterEquals($container, 'proxy_address', $proxyAddress);
}

public function testLoadConfigWithoutProxyAddressOption()
{
$config = array(
'auth_token' => uniqid(),
);
$container = $this->getEmptyTestContainer();
$this->loadConfigIntoContainer($config, $container);

$this->assertContainerParameterEquals($container, 'proxy_address', null);
}

/**
* @param ContainerBuilder $container
* @param string $parameterName
* @param mixed $value
*/
protected function assertContainerParameterEquals( ContainerBuilder $container, $parameterName, $value )
{
$parameterValue = $container->getParameter('mannew_hipchat.' . $parameterName);
$this->assertEquals($value, $parameterValue);
}

/**
Expand All @@ -46,12 +106,21 @@ protected function setUp()
*
* @return ContainerBuilder
*/
private function getContainer()
protected function getEmptyTestContainer()
{
$container = new ContainerBuilder();
$container->setParameter('kernel.cache_dir', sys_get_temp_dir());
$container->setParameter('kernel.bundles', array());

return $container;
}

/**
* @param array $config
* @param ContainerBuilder $container
*/
protected function loadConfigIntoContainer( array $config, ContainerBuilder $container )
{
$this->extension->load(array($config), $container);
}
}

0 comments on commit a4b121b

Please sign in to comment.