diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index 2adb5fb..0f6135b 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -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; diff --git a/DependencyInjection/MannewHipchatExtension.php b/DependencyInjection/MannewHipchatExtension.php index 9c77001..4a8ff89 100644 --- a/DependencyInjection/MannewHipchatExtension.php +++ b/DependencyInjection/MannewHipchatExtension.php @@ -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'] + ); } } diff --git a/README.md b/README.md index 04d85a4..3e2e6a9 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/Resources/config/hipchat.xml b/Resources/config/hipchat.xml index 542d209..a622444 100644 --- a/Resources/config/hipchat.xml +++ b/Resources/config/hipchat.xml @@ -9,6 +9,12 @@ %mannew_hipchat.auth_token% + + %mannew_hipchat.verify_ssl% + + + %mannew_hipchat.proxy_address% + diff --git a/Tests/DependencyInjection/MannewHipchatExtensionTest.php b/Tests/DependencyInjection/MannewHipchatExtensionTest.php index 13a56d2..4c31f93 100644 --- a/Tests/DependencyInjection/MannewHipchatExtensionTest.php +++ b/Tests/DependencyInjection/MannewHipchatExtensionTest.php @@ -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() @@ -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); } /** @@ -46,7 +106,7 @@ protected function setUp() * * @return ContainerBuilder */ - private function getContainer() + protected function getEmptyTestContainer() { $container = new ContainerBuilder(); $container->setParameter('kernel.cache_dir', sys_get_temp_dir()); @@ -54,4 +114,13 @@ private function getContainer() return $container; } + + /** + * @param array $config + * @param ContainerBuilder $container + */ + protected function loadConfigIntoContainer( array $config, ContainerBuilder $container ) + { + $this->extension->load(array($config), $container); + } }