From 8b2db106188756b91c5cd962d58c105c70d420ad Mon Sep 17 00:00:00 2001 From: Paul Brand Date: Mon, 7 Jul 2014 14:43:39 +0200 Subject: [PATCH 1/2] Add verify_ssl and proxy_address bundle options. This will allow setting these options on the HipChat service. The HipChat package requirement in Composer is updated to dev. This is needed because the verify_ssl en proxy options are not present in the latest stable tag. --- DependencyInjection/Configuration.php | 8 ++++ .../MannewHipchatExtension.php | 8 ++++ README.md | 2 + Resources/config/hipchat.xml | 6 +++ .../MannewHipchatExtensionTest.php | 48 +++++++++++++++++-- composer.json | 2 +- 6 files changed, 68 insertions(+), 6 deletions(-) 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..f3e9621 100644 --- a/Tests/DependencyInjection/MannewHipchatExtensionTest.php +++ b/Tests/DependencyInjection/MannewHipchatExtensionTest.php @@ -21,16 +21,54 @@ public function testLoadConfigThrowsExceptionOnMissingAuthToken() $this->extension->load(array($config), $container = $this->getContainer()); } + public function testHipChatServiceIsDefined() + { + $config = array('auth_token' => uniqid()); + $container = $this->getContainer(); + $this->extension->load(array($config), $container); + + $this->assertTrue($container->hasDefinition('hipchat')); + } + public function testLoadConfigWithAuthToken() { $testToken = 'testtoken'; - $config = array( - 'auth_token' => $testToken - ); + $this->assertContainerParameterValueEquals('auth_token', $testToken); + } + + public function testLoadConfigWithVerifySSLOption() + { + $this->assertContainerParameterValueEquals('verify_ssl', false); + $this->assertContainerParameterValueEquals('verify_ssl', true); + } + + public function testLoadConfigWithProxyAddressOption() + { + $this->assertContainerParameterValueEquals('proxy_address', '127.0.0.1:8888'); + } + + public function testLoadConfigWithoutProxyAddressOption() + { + $config = array('auth_token' => uniqid()); $this->extension->load(array($config), $container = $this->getContainer()); + $parameterValue = $container->getParameter('mannew_hipchat.proxy_address'); - $this->assertEquals($testToken, $container->getParameter('mannew_hipchat.auth_token')); - $this->assertTrue($container->hasDefinition('hipchat')); + $this->assertNull($parameterValue); + } + + /** + * @param string $parameterName + * @param string $expectedValue + */ + protected function assertContainerParameterValueEquals( $parameterName, $expectedValue ) + { + $config = array('auth_token' => uniqid()); + $config[$parameterName] = $expectedValue; + $parameterName = 'mannew_hipchat.' . $parameterName; + $this->extension->load(array($config), $container = $this->getContainer()); + + $parameterValue = $container->getParameter($parameterName); + $this->assertEquals($expectedValue, $parameterValue); } /** diff --git a/composer.json b/composer.json index 79b6d52..09fa6bc 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Bundle to integrate the HipChat PHP library for their REST API.", "require": { "symfony/framework-bundle": "~2.1", - "hipchat/hipchat-php": ">=1.0.0" + "hipchat/hipchat-php": ">=1.0.0@dev" }, "license": "MIT", "authors": [ From b9a7f64fa9ff4a3be1d1972b4795bdb22db31442 Mon Sep 17 00:00:00 2001 From: Paul Brand Date: Fri, 11 Jul 2014 17:43:09 +0200 Subject: [PATCH 2/2] Update Composer hipchat-php dependency to use stable tag. Refactor tests. --- .../MannewHipchatExtensionTest.php | 79 +++++++++++++------ composer.json | 2 +- 2 files changed, 56 insertions(+), 25 deletions(-) diff --git a/Tests/DependencyInjection/MannewHipchatExtensionTest.php b/Tests/DependencyInjection/MannewHipchatExtensionTest.php index f3e9621..4c31f93 100644 --- a/Tests/DependencyInjection/MannewHipchatExtensionTest.php +++ b/Tests/DependencyInjection/MannewHipchatExtensionTest.php @@ -18,57 +18,79 @@ 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->getContainer(); - $this->extension->load(array($config), $container); - - $this->assertTrue($container->hasDefinition('hipchat')); + $config = array( + 'auth_token' => uniqid() + ); + $container = $this->getEmptyTestContainer(); + $this->loadConfigIntoContainer($config, $container); + $containerHasDefinitionForHipchatService = $container->hasDefinition('hipchat'); + + $this->assertTrue($containerHasDefinitionForHipchatService); } public function testLoadConfigWithAuthToken() { $testToken = 'testtoken'; - $this->assertContainerParameterValueEquals('auth_token', $testToken); + $config = array( + 'auth_token' => $testToken + ); + $container = $this->getEmptyTestContainer(); + $this->loadConfigIntoContainer($config, $container); + + $this->assertContainerParameterEquals($container, 'auth_token', $testToken); } public function testLoadConfigWithVerifySSLOption() { - $this->assertContainerParameterValueEquals('verify_ssl', false); - $this->assertContainerParameterValueEquals('verify_ssl', true); + $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() { - $this->assertContainerParameterValueEquals('proxy_address', '127.0.0.1:8888'); + $proxyAddress = 'http://127.0.0.1:8888'; + $config = array( + 'proxy_address' => $proxyAddress, + 'auth_token' => uniqid(), + ); + $container = $this->getEmptyTestContainer(); + $this->loadConfigIntoContainer($config, $container); + + $this->assertContainerParameterEquals($container, 'proxy_address', $proxyAddress); } public function testLoadConfigWithoutProxyAddressOption() { - $config = array('auth_token' => uniqid()); - $this->extension->load(array($config), $container = $this->getContainer()); - $parameterValue = $container->getParameter('mannew_hipchat.proxy_address'); + $config = array( + 'auth_token' => uniqid(), + ); + $container = $this->getEmptyTestContainer(); + $this->loadConfigIntoContainer($config, $container); - $this->assertNull($parameterValue); + $this->assertContainerParameterEquals($container, 'proxy_address', null); } /** + * @param ContainerBuilder $container * @param string $parameterName - * @param string $expectedValue + * @param mixed $value */ - protected function assertContainerParameterValueEquals( $parameterName, $expectedValue ) + protected function assertContainerParameterEquals( ContainerBuilder $container, $parameterName, $value ) { - $config = array('auth_token' => uniqid()); - $config[$parameterName] = $expectedValue; - $parameterName = 'mannew_hipchat.' . $parameterName; - $this->extension->load(array($config), $container = $this->getContainer()); - - $parameterValue = $container->getParameter($parameterName); - $this->assertEquals($expectedValue, $parameterValue); + $parameterValue = $container->getParameter('mannew_hipchat.' . $parameterName); + $this->assertEquals($value, $parameterValue); } /** @@ -84,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()); @@ -92,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); + } } diff --git a/composer.json b/composer.json index 09fa6bc..79b6d52 100644 --- a/composer.json +++ b/composer.json @@ -3,7 +3,7 @@ "description": "Bundle to integrate the HipChat PHP library for their REST API.", "require": { "symfony/framework-bundle": "~2.1", - "hipchat/hipchat-php": ">=1.0.0@dev" + "hipchat/hipchat-php": ">=1.0.0" }, "license": "MIT", "authors": [