Skip to content
This repository has been archived by the owner on Oct 6, 2021. It is now read-only.

Commit

Permalink
Merge pull request #27 from M6Web/feature/keyspace-and-client-management
Browse files Browse the repository at this point in the history
Allow keyspace to be null
  • Loading branch information
NastasiaSaby authored Nov 15, 2016
2 parents 0fa75e8 + c95374c commit 639bca9
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 10 deletions.
2 changes: 1 addition & 1 deletion src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getConfigTreeBuilder()
->end()
->children()
->booleanNode('persistent_sessions')->defaultValue(true)->end()
->scalarNode('keyspace')->isRequired()->cannotBeEmpty()->end()
->scalarNode('keyspace')->defaultValue(null)->end()
->scalarNode('load_balancing')
->defaultValue('round-robin')
->validate()
Expand Down
7 changes: 7 additions & 0 deletions src/Tests/Fixtures/default-config-without-keyspace.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
m6web_cassandra:
clients:
client_test:
contact_endpoints:
- '127.0.0.1'
- '127.0.0.2'
- '127.0.0.3'
74 changes: 65 additions & 9 deletions src/Tests/Units/DependencyInjection/M6WebCassandraExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,18 @@

use M6Web\Bundle\CassandraBundle\DependencyInjection\M6WebCassandraExtension as TestedClass;

/**
* Class M6WebCassandraExtension
* @package M6Web\Bundle\CassandraBundle\Tests\Units\DependencyInjection
*/
class M6WebCassandraExtension extends test
{
/**
* @return void
*/
public function testDefaultConfig()
{
$container = $this->getContainerForConfiguation('default-config');
$container = $this->getContainerForConfiguration('default-config');
$container->compile();

$this
Expand Down Expand Up @@ -64,9 +71,32 @@ public function testDefaultConfig()
;
}

/**
* @return void
*/
public function testShouldGetADefaultNullKeyspaceWhenNoKeyspaceGiven()
{
$container = $this->getContainerForConfiguration('default-config-without-keyspace');
$container->compile();

$this
->boolean($container->has('m6web_cassandra.client.client_test'))
->isTrue()
->array($arguments = $container->getDefinition('m6web_cassandra.client.client_test')->getArgument(0))
->hasSize(12)
->hasKeys($this->getDefaultConfigKeys())
->notHasKeys(['default_timeout'])
->variable($arguments['keyspace'])
->isNull()
;
}

/**
* @return void
*/
public function testOverrideConfig()
{
$container = $this->getContainerForConfiguation('override-config');
$container = $this->getContainerForConfiguration('override-config');
$container->compile();

$this
Expand Down Expand Up @@ -133,9 +163,12 @@ public function testOverrideConfig()
;
}

/**
* @return void
*/
public function testOverrideDefaultEndPointsConfig()
{
$container = $this->getContainerForConfiguation('override-config-with-import');
$container = $this->getContainerForConfiguration('override-config-with-import');
$container->compile();

$this
Expand All @@ -155,9 +188,12 @@ public function testOverrideDefaultEndPointsConfig()
;
}

/**
* @return void
*/
public function testMulticlientsConfig()
{
$container = $this->getContainerForConfiguation('multiclients');
$container = $this->getContainerForConfiguration('multiclients');
$container->compile();

$this
Expand Down Expand Up @@ -205,6 +241,9 @@ public function testMulticlientsConfig()
}

/**
* @param array $configs
* @return void
*
* @dataProvider unexpectedConfigValueDataProvider
*/
public function testUnexpectedValueConfig($configs)
Expand All @@ -213,13 +252,15 @@ public function testUnexpectedValueConfig($configs)
$container = new ContainerBuilder($parameterBag);

$this->if($extension = new TestedClass())
->exception(function() use($extension, $configs, $container) {
->exception(function () use ($extension, $configs, $container) {
$extension->load($configs, $container);
})
->isInstanceOf('\Symfony\Component\Config\Definition\Exception\InvalidConfigurationException');

}

/**
* @return void
*/
public function testInvalidConfig()
{
// no option for dc aware load balancing
Expand All @@ -237,15 +278,19 @@ public function testInvalidConfig()
$container = new ContainerBuilder($parameterBag);

$this->if($extension = new TestedClass())
->exception(function() use($extension, $configs, $container) {
->exception(function () use ($extension, $configs, $container) {
$extension->load($configs, $container);
})
->isInstanceOf('\InvalidArgumentException');
}

/**
* @return void
* @throws \Throwable
*/
public function testConfigurator()
{
$container = $this->getContainerForConfiguation('default-config');
$container = $this->getContainerForConfiguration('default-config');
$container->compile();

$this
Expand All @@ -255,6 +300,9 @@ public function testConfigurator()
->isInstanceOf('Cassandra\DefaultCluster');
}

/**
* @return array
*/
protected function unexpectedConfigValueDataProvider()
{
return [
Expand All @@ -281,7 +329,11 @@ protected function unexpectedConfigValueDataProvider()
];
}

protected function getContainerForConfiguation($fixtureName)
/**
* @param $fixtureName
* @return ContainerBuilder
*/
protected function getContainerForConfiguration($fixtureName)
{
$extension = new TestedClass();

Expand All @@ -296,6 +348,10 @@ protected function getContainerForConfiguation($fixtureName)
return $container;
}

/**
* @param array $keySup
* @return array
*/
protected function getDefaultConfigKeys(array $keySup = [])
{
return array_merge(
Expand Down

0 comments on commit 639bca9

Please sign in to comment.