From 9ae80d394210a402ab20ec8574d2f1adf593ad4f Mon Sep 17 00:00:00 2001 From: Sandro Keil Date: Fri, 9 Dec 2016 00:09:37 +0100 Subject: [PATCH 1/2] update docs --- CHANGELOG.md | 21 +++++++++++++++++++++ README.md | 2 +- doc/book/intro.md | 2 +- doc/book/quick-start.md | 8 ++++---- doc/bookdown.json | 4 ++-- 5 files changed, 29 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1a0a2cf..15dad0a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,27 @@ All notable changes to this project will be documented in this file, in reverse chronological order by release. +## 2.0.1 (2016-12-09) +This release contains **no** BC break. + +### Added + +* More test cases for iterable return type and `\Iterator` objects + +### Deprecated + +* Nothing + +### Removed + +* Nothing + +### Fixed + +* [#34](https://github.com/sandrokeil/interop-config/issue/34): Inconsistent return type in `defaultOptions()` + * `defaultOptions()` method return type is `iterable` but `array` is still valid + + ## 2.0.0 (2016-12-06) To upgrade from version 1.x to version 2.x you have to add the PHP scalar types of the interfaces to your implemented factory methods. diff --git a/README.md b/README.md index c20ea72..5b0420b 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,7 @@ You should have coding conventions and you should have config conventions. If no ## Installation -Installation of this module uses composer. For composer documentation, please refer to +The suggested installation method is via composer. For composer documentation, please refer to [getcomposer.org](http://getcomposer.org/). Run `composer require sandrokeil/interop-config` to install interop-config. Version `1.x` is for PHP < 7.1 and Version `2.x` is for PHP >= 7.1. diff --git a/doc/book/intro.md b/doc/book/intro.md index bdb7821..964934e 100644 --- a/doc/book/intro.md +++ b/doc/book/intro.md @@ -36,7 +36,7 @@ You should have coding conventions and you should have config conventions. If no `interop-config` is universally applicable! See further documentation for more details. ## Installation -Installation of this library uses Composer. For Composer documentation, please refer to +The suggested installation method is via composer. For composer documentation, please refer to [getcomposer.org](http://getcomposer.org/). Run `composer require sandrokeil/interop-config` to install interop-config. diff --git a/doc/book/quick-start.md b/doc/book/quick-start.md index 1a3f2b9..8cf5e82 100644 --- a/doc/book/quick-start.md +++ b/doc/book/quick-start.md @@ -39,14 +39,14 @@ class MyAwesomeFactory implements RequiresConfigId public function dimensions() : iterable { return ['vendor-package']; - } - - public function canRetrieveOptions($config, $configId = null) : bool + } + + public function canRetrieveOptions($config, string $configId = null) : bool { // custom implementation depending on specifications } - public function options($config, $configId = null) + public function options($config, string $configId = null) { // custom implementation depending on specifications } diff --git a/doc/bookdown.json b/doc/bookdown.json index 84ffe08..ff0ecb3 100644 --- a/doc/bookdown.json +++ b/doc/bookdown.json @@ -1,5 +1,5 @@ { - "title": "interop-config", + "title": "interop-config - configurable factories", "content": [ {"getting-started": "book/getting-started/bookdown.json"}, {"reference": "book/reference/bookdown.json"}, @@ -8,5 +8,5 @@ "target": "./html", "tocDepth": 2, "template": "../vendor/tobiju/bookdown-bootswatch-templates/templates/main.php", - "copyright": "Copyright (c) 2015-2016 Sandro Keil
Powered by Bookdown Bootswatch Templates" + "copyright": "Visit interop-config on GitHub
Copyright (c) 2015-2016 Sandro Keil
Powered by Bookdown Bootswatch Templates" } From 5511eb4c143b6def52afbcfdeaf487139bcfef2b Mon Sep 17 00:00:00 2001 From: Sandro Keil Date: Fri, 9 Dec 2016 00:19:35 +0100 Subject: [PATCH 2/2] fix #34 inconsistency on defaultOptions return type, now it's also iterable --- src/ConfigurationTrait.php | 10 +- src/ProvidesDefaultOptions.php | 4 +- test/ConfigurationTraitTest.php | 173 ++++++++++++++---- .../ConnectionDefaultOptionsConfiguration.php | 2 +- ...eArrayIteratorContainerIdConfiguration.php | 4 +- test/TestAsset/OnlyIterator.php | 52 ++++++ .../UniversalContainerIdConfiguration.php | 83 +++++++++ test/testing.config.php.dist | 14 ++ 8 files changed, 298 insertions(+), 44 deletions(-) create mode 100644 test/TestAsset/OnlyIterator.php create mode 100644 test/TestAsset/UniversalContainerIdConfiguration.php diff --git a/src/ConfigurationTrait.php b/src/ConfigurationTrait.php index 2b1e5a8..9f44c6d 100644 --- a/src/ConfigurationTrait.php +++ b/src/ConfigurationTrait.php @@ -13,6 +13,7 @@ use ArrayAccess; use Interop\Config\Exception; +use Iterator; /** * ConfigurationTrait which retrieves options from configuration, see interface \Interop\Config\RequiresConfig @@ -42,6 +43,7 @@ abstract public function dimensions(): iterable; public function canRetrieveOptions($config, string $configId = null): bool { $dimensions = $this->dimensions(); + $dimensions = $dimensions instanceof Iterator ? iterator_to_array($dimensions) : $dimensions; if ($this instanceof RequiresConfigId) { $dimensions[] = $configId; @@ -82,6 +84,7 @@ public function canRetrieveOptions($config, string $configId = null): bool public function options($config, string $configId = null) { $dimensions = $this->dimensions(); + $dimensions = $dimensions instanceof Iterator ? iterator_to_array($dimensions) : $dimensions; if ($this instanceof RequiresConfigId) { $dimensions[] = $configId; @@ -115,7 +118,12 @@ public function options($config, string $configId = null) } if ($this instanceof ProvidesDefaultOptions) { - $config = array_replace_recursive($this->defaultOptions(), $config); + $options = $this->defaultOptions(); + + $config = array_replace_recursive( + $options instanceof Iterator ? iterator_to_array($options) : (array)$options, + (array)$config + ); } return $config; } diff --git a/src/ProvidesDefaultOptions.php b/src/ProvidesDefaultOptions.php index dc7165f..cb96e0e 100644 --- a/src/ProvidesDefaultOptions.php +++ b/src/ProvidesDefaultOptions.php @@ -22,7 +22,7 @@ interface ProvidesDefaultOptions /** * Returns a list of default options, which are merged in \Interop\Config\RequiresConfig::options() * - * @return mixed[] List with default options and values, can be nested + * @return iterable List with default options and values, can be nested */ - public function defaultOptions(): array; + public function defaultOptions(): iterable; } diff --git a/test/ConfigurationTraitTest.php b/test/ConfigurationTraitTest.php index 7530426..779d0d6 100644 --- a/test/ConfigurationTraitTest.php +++ b/test/ConfigurationTraitTest.php @@ -17,6 +17,7 @@ use Interop\Config\Exception\UnexpectedValueException; use InteropTest\Config\TestAsset\ConnectionConfiguration; use InteropTest\Config\TestAsset\ConnectionContainerIdConfiguration; +use InteropTest\Config\TestAsset\ConnectionDefaultOptionsConfiguration; use InteropTest\Config\TestAsset\ConnectionDefaultOptionsMandatoryContainetIdConfiguration; use InteropTest\Config\TestAsset\ConnectionMandatoryConfiguration; use InteropTest\Config\TestAsset\ConnectionMandatoryContainerIdConfiguration; @@ -26,6 +27,7 @@ use InteropTest\Config\TestAsset\PackageDefaultAndMandatoryOptionsConfiguration; use InteropTest\Config\TestAsset\PackageDefaultOptionsConfiguration; use InteropTest\Config\TestAsset\PlainConfiguration; +use InteropTest\Config\TestAsset\UniversalContainerIdConfiguration; use PHPUnit_Framework_TestCase as TestCase; /** @@ -136,9 +138,9 @@ public function testOptionsThrowsInvalidArgumentExIfConfigIdIsProvidedButRequire * Tests options() should throw exception if config id is missing but RequiresConfigId interface is implemented * * @dataProvider providerConfig - * @covers \Interop\Config\ConfigurationTrait::options - * @covers \Interop\Config\Exception\OptionNotFoundException::missingOptions - * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions + * @covers \Interop\Config\ConfigurationTrait::options + * @covers \Interop\Config\Exception\OptionNotFoundException::missingOptions + * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions */ public function testOptionsThrowsOptionNotFoundExceptionIfConfigIdIsMissingWithRequiresConfigId($config): void { @@ -275,8 +277,8 @@ public function testOptionsThrowsUnexpectedValueExceptionIfRetrievedOptionsNotAn * Tests if options() works with container id * * @dataProvider providerConfig - * @covers \Interop\Config\ConfigurationTrait::options - * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions + * @covers \Interop\Config\ConfigurationTrait::options + * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions */ public function testOptionsReturnsDataWithContainerId($config): void { @@ -294,8 +296,8 @@ public function testOptionsReturnsDataWithContainerId($config): void * Tests if options() works without container id * * @dataProvider providerConfig - * @covers \Interop\Config\ConfigurationTrait::options - * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions + * @covers \Interop\Config\ConfigurationTrait::options + * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions */ public function testOptionsReturnsData($config): void { @@ -312,8 +314,8 @@ public function testOptionsReturnsData($config): void * Tests if options() works with flexible dimensions * * @dataProvider providerConfig - * @covers \Interop\Config\ConfigurationTrait::options - * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions + * @covers \Interop\Config\ConfigurationTrait::options + * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions */ public function testOptionsReturnsDataWithFlexibleDimensions($config): void { @@ -331,8 +333,8 @@ public function testOptionsReturnsDataWithFlexibleDimensions($config): void * Tests if options() works with no dimensions * * @dataProvider providerConfig - * @covers \Interop\Config\ConfigurationTrait::options - * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions + * @covers \Interop\Config\ConfigurationTrait::options + * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions */ public function testOptionsReturnsDataWithNoDimensions($config): void { @@ -350,8 +352,8 @@ public function testOptionsReturnsDataWithNoDimensions($config): void * Tests if options() works with default options * * @dataProvider providerConfig - * @covers \Interop\Config\ConfigurationTrait::options - * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions + * @covers \Interop\Config\ConfigurationTrait::options + * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions */ public function testOptionsReturnsDataWithDefaultOptions($config): void { @@ -364,6 +366,7 @@ public function testOptionsReturnsDataWithDefaultOptions($config): void $options = $stub->options($config, 'orm_default'); $defaultOptions = $stub->defaultOptions(); + self::assertCount(2, $options); self::assertArrayHasKey('params', $options); self::assertSame($options['params']['host'], $defaultOptions['params']['host']); self::assertSame($options['params']['port'], $defaultOptions['params']['port']); @@ -380,6 +383,7 @@ public function testOptionsReturnsDataWithDefaultOptions($config): void self::assertTrue($stub->canRetrieveOptions($config, 'orm_default')); $options = $stub->options($config, 'orm_default'); + self::assertCount(2, $options); self::assertArrayHasKey('params', $options); self::assertSame($options['params']['host'], $defaultOptions['params']['host']); self::assertSame($options['params']['port'], $defaultOptions['params']['port']); @@ -404,6 +408,7 @@ public function testOptionsReturnsPackageDataWithDefaultOptionsIfNoConfiguration $options = $stub->options([]); + self::assertCount(2, $options); self::assertSame($expected, $options); } @@ -411,8 +416,8 @@ public function testOptionsReturnsPackageDataWithDefaultOptionsIfNoConfiguration * Tests if options() works default options and default options not override provided options * * @dataProvider providerConfig - * @covers \Interop\Config\ConfigurationTrait::options - * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions + * @covers \Interop\Config\ConfigurationTrait::options + * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions */ public function testOptionsThatDefaultOptionsNotOverrideProvidedOptions($config): void { @@ -421,6 +426,7 @@ public function testOptionsThatDefaultOptionsNotOverrideProvidedOptions($config) self::assertTrue($stub->canRetrieveOptions($config, 'orm_default')); $options = $stub->options($config, 'orm_default'); + self::assertCount(2, $options); self::assertArrayHasKey('params', $options); self::assertSame( $options['params']['host'], @@ -440,9 +446,9 @@ public function testOptionsThatDefaultOptionsNotOverrideProvidedOptions($config) * Tests if options() works with mandatory options interface * * @dataProvider providerConfig - * @covers \Interop\Config\ConfigurationTrait::options - * @covers \Interop\Config\ConfigurationTrait::checkMandatoryOptions - * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions + * @covers \Interop\Config\ConfigurationTrait::options + * @covers \Interop\Config\ConfigurationTrait::checkMandatoryOptions + * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions */ public function testOptionsChecksMandatoryOptions($config): void { @@ -451,6 +457,7 @@ public function testOptionsChecksMandatoryOptions($config): void self::assertTrue($stub->canRetrieveOptions($config)); $options = $stub->options($config); + self::assertCount(1, $options); self::assertArrayHasKey('orm_default', $options); } @@ -458,9 +465,9 @@ public function testOptionsChecksMandatoryOptions($config): void * Tests if options() works with mandatory options interface * * @dataProvider providerConfig - * @covers \Interop\Config\ConfigurationTrait::options - * @covers \Interop\Config\ConfigurationTrait::checkMandatoryOptions - * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions + * @covers \Interop\Config\ConfigurationTrait::options + * @covers \Interop\Config\ConfigurationTrait::checkMandatoryOptions + * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions */ public function testOptionsChecksMandatoryOptionsWithContainerId($config): void { @@ -469,6 +476,7 @@ public function testOptionsChecksMandatoryOptionsWithContainerId($config): void self::assertTrue($stub->canRetrieveOptions($config, 'orm_default')); $options = $stub->options($config, 'orm_default'); + self::assertCount(2, $options); self::assertArrayHasKey('driverClass', $options); self::assertArrayHasKey('params', $options); } @@ -477,10 +485,10 @@ public function testOptionsChecksMandatoryOptionsWithContainerId($config): void * Tests if options() throws a runtime exception if mandatory option is missing * * @dataProvider providerConfig - * @covers \Interop\Config\ConfigurationTrait::options - * @covers \Interop\Config\ConfigurationTrait::checkMandatoryOptions - * @covers \Interop\Config\Exception\MandatoryOptionNotFoundException::missingOption - * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions + * @covers \Interop\Config\ConfigurationTrait::options + * @covers \Interop\Config\ConfigurationTrait::checkMandatoryOptions + * @covers \Interop\Config\Exception\MandatoryOptionNotFoundException::missingOption + * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions */ public function testOptionsThrowsMandatoryOptionNotFoundExceptionIfMandatoryOptionIsMissing($config): void { @@ -498,10 +506,10 @@ public function testOptionsThrowsMandatoryOptionNotFoundExceptionIfMandatoryOpti * Tests if options() throws a runtime exception if a recursive mandatory option is missing * * @dataProvider providerConfig - * @covers \Interop\Config\ConfigurationTrait::options - * @covers \Interop\Config\ConfigurationTrait::checkMandatoryOptions - * @covers \Interop\Config\Exception\MandatoryOptionNotFoundException::missingOption - * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions + * @covers \Interop\Config\ConfigurationTrait::options + * @covers \Interop\Config\ConfigurationTrait::checkMandatoryOptions + * @covers \Interop\Config\Exception\MandatoryOptionNotFoundException::missingOption + * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions */ public function testOptionsThrowsMandatoryOptionNotFoundExceptionIfMandatoryOptionRecursiveIsMissing($config): void { @@ -519,9 +527,9 @@ public function testOptionsThrowsMandatoryOptionNotFoundExceptionIfMandatoryOpti * Tests options() with recursive mandatory options check * * @dataProvider providerConfig - * @covers \Interop\Config\ConfigurationTrait::options - * @covers \Interop\Config\ConfigurationTrait::checkMandatoryOptions - * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions + * @covers \Interop\Config\ConfigurationTrait::options + * @covers \Interop\Config\ConfigurationTrait::checkMandatoryOptions + * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions */ public function testOptionsWithRecursiveMandatoryOptionCheck($config): void { @@ -535,9 +543,9 @@ public function testOptionsWithRecursiveMandatoryOptionCheck($config): void * Tests options() with recursive mandatory options as array iterator * * @dataProvider providerConfig - * @covers \Interop\Config\ConfigurationTrait::options - * @covers \Interop\Config\ConfigurationTrait::checkMandatoryOptions - * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions + * @covers \Interop\Config\ConfigurationTrait::options + * @covers \Interop\Config\ConfigurationTrait::checkMandatoryOptions + * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions */ public function testOptionsWithRecursiveArrayIteratorMandatoryOptionCheck($config): void { @@ -548,11 +556,11 @@ public function testOptionsWithRecursiveArrayIteratorMandatoryOptionCheck($confi } /** - * Tests if options() throws a runtime exception if a recursive mandatory option is missing + * Tests if optionsWithFallback() * * @dataProvider providerConfig - * @covers \Interop\Config\ConfigurationTrait::optionsWithFallback - * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions + * @covers \Interop\Config\ConfigurationTrait::optionsWithFallback + * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions */ public function testOptionsWithFallback($config): void { @@ -590,11 +598,100 @@ public function testOptionsThrowsMandatoryOptionNotFoundExceptionIfOptionsAreEmp $stub->options($config, 'orm_default'); } + /** + * Tests if options() works with an empty \ArrayAccess object and default options. + * + * @covers \Interop\Config\ConfigurationTrait::options + */ + public function testEmptyArrayAccessWithDefaultOptions() + { + $stub = new ConnectionDefaultOptionsConfiguration(); + + $config = new \ArrayIterator([]); + + $options = $stub->options($config); + + self::assertCount(1, $options); + self::assertArrayHasKey('params', $options); + + self::assertSame( + $options['params']['host'], + 'awesomehost' + ); + self::assertSame( + $options['params']['port'], + '4444' + ); + } + + /** + * Tests if options() works with iterable objects like \ArrayIterator or \ArrayObject + * + * @dataProvider providerConfigObjects + * @covers \Interop\Config\ConfigurationTrait::options + * @covers \Interop\Config\ConfigurationTrait::canRetrieveOptions + */ + public function testOptionsWithObjects($config, $type): void + { + $stub = new UniversalContainerIdConfiguration($type); + + self::assertTrue($stub->canRetrieveOptions($config, 'orm_default')); + $options = $stub->options($config, 'orm_default'); + + self::assertCount(2, $options); + self::assertArrayHasKey('driverClass', $options); + self::assertArrayHasKey('params', $options); + + $driverClass = 'Doctrine\DBAL\Driver\PDOMySql\Driver'; + $host = 'localhost'; + $dbname = 'database'; + $user = 'username'; + $password = 'password'; + $port = '4444'; + + if ($type !== UniversalContainerIdConfiguration::TYPE_ONLY_ITERATOR) { + $driverClass = $config['doctrine']['connection']['orm_default']['driverClass']; + $host = $config['doctrine']['connection']['orm_default']['params']['host']; + $dbname = $config['doctrine']['connection']['orm_default']['params']['dbname']; + $user = $config['doctrine']['connection']['orm_default']['params']['user']; + $password = $config['doctrine']['connection']['orm_default']['params']['password']; + } + + self::assertSame($options['driverClass'], $driverClass); + self::assertSame($options['params']['host'], $host); + self::assertSame($options['params']['port'], $port); + self::assertSame($options['params']['dbname'], $dbname); + self::assertSame($options['params']['user'], $user); + self::assertSame($options['params']['password'], $password); + } + public function providerConfig(): array { return [ [$this->getTestConfig()], [new \ArrayObject($this->getTestConfig())], + [new \ArrayIterator($this->getTestConfig())], + ]; + } + + public function providerConfigObjects(): array + { + return [ + [$this->getTestConfig(), UniversalContainerIdConfiguration::TYPE_ARRAY_ARRAY], + [new \ArrayObject($this->getTestConfig()), UniversalContainerIdConfiguration::TYPE_ARRAY_ARRAY], + [new \ArrayIterator($this->getTestConfig()), UniversalContainerIdConfiguration::TYPE_ARRAY_ARRAY], + + [$this->getTestConfig(), UniversalContainerIdConfiguration::TYPE_ARRAY_OBJECT], + [new \ArrayObject($this->getTestConfig()), UniversalContainerIdConfiguration::TYPE_ARRAY_OBJECT], + [new \ArrayIterator($this->getTestConfig()), UniversalContainerIdConfiguration::TYPE_ARRAY_OBJECT], + + [$this->getTestConfig(), UniversalContainerIdConfiguration::TYPE_ARRAY_ITERATOR], + [new \ArrayObject($this->getTestConfig()), UniversalContainerIdConfiguration::TYPE_ARRAY_ITERATOR], + [new \ArrayIterator($this->getTestConfig()), UniversalContainerIdConfiguration::TYPE_ARRAY_ITERATOR], + + [$this->getTestConfig(), UniversalContainerIdConfiguration::TYPE_ONLY_ITERATOR], + [new \ArrayObject($this->getTestConfig()), UniversalContainerIdConfiguration::TYPE_ONLY_ITERATOR], + [new \ArrayIterator($this->getTestConfig()), UniversalContainerIdConfiguration::TYPE_ONLY_ITERATOR], ]; } diff --git a/test/TestAsset/ConnectionDefaultOptionsConfiguration.php b/test/TestAsset/ConnectionDefaultOptionsConfiguration.php index 3f69adf..66826e9 100644 --- a/test/TestAsset/ConnectionDefaultOptionsConfiguration.php +++ b/test/TestAsset/ConnectionDefaultOptionsConfiguration.php @@ -24,7 +24,7 @@ public function dimensions(): iterable return ['doctrine', 'connection']; } - public function defaultOptions(): array + public function defaultOptions(): iterable { return [ 'params' => [ diff --git a/test/TestAsset/ConnectionMandatoryRecursiveArrayIteratorContainerIdConfiguration.php b/test/TestAsset/ConnectionMandatoryRecursiveArrayIteratorContainerIdConfiguration.php index 3cef976..21d0719 100644 --- a/test/TestAsset/ConnectionMandatoryRecursiveArrayIteratorContainerIdConfiguration.php +++ b/test/TestAsset/ConnectionMandatoryRecursiveArrayIteratorContainerIdConfiguration.php @@ -24,7 +24,7 @@ class ConnectionMandatoryRecursiveArrayIteratorContainerIdConfiguration implemen */ public function dimensions(): iterable { - return ['doctrine', 'connection']; + return new \ArrayIterator(['doctrine', 'connection']); } /** @@ -32,6 +32,6 @@ public function dimensions(): iterable */ public function mandatoryOptions(): iterable { - return ['params' => ['user', 'dbname'], 'driverClass']; + return new \ArrayIterator(['params' => ['user', 'dbname'], 'driverClass']); } } diff --git a/test/TestAsset/OnlyIterator.php b/test/TestAsset/OnlyIterator.php new file mode 100644 index 0000000..c6150fd --- /dev/null +++ b/test/TestAsset/OnlyIterator.php @@ -0,0 +1,52 @@ +data = $data; + } + + public function current() + { + return current($this->data); + } + + public function next() + { + next($this->data); + } + + public function key() + { + return key($this->data); + } + + public function valid() + { + return current($this->data); + } + + public function rewind() + { + reset($this->data); + } + +} diff --git a/test/TestAsset/UniversalContainerIdConfiguration.php b/test/TestAsset/UniversalContainerIdConfiguration.php new file mode 100644 index 0000000..4c59cbd --- /dev/null +++ b/test/TestAsset/UniversalContainerIdConfiguration.php @@ -0,0 +1,83 @@ + ['user', 'dbname'], + 'driverClass', + ]; + + private static $defaultOptions = [ + 'params' => [ + 'host' => 'awesomehost', + 'port' => '4444', + ], + ]; + + private $type; + + public function __construct(int $type) + { + $this->type = $type; + } + + public function dimensions(): iterable + { + return $this->getData('dimensions'); + } + + public function mandatoryOptions(): iterable + { + return $this->getData('mandatoryOptions'); + } + + public function defaultOptions(): iterable + { + return $this->getData('defaultOptions'); + } + + private function getData($name) + { + switch ($this->type) { + case self::TYPE_ARRAY_ITERATOR: + return new \ArrayIterator(self::$$name); + break; + case self::TYPE_ARRAY_OBJECT: + return new \ArrayObject(self::$$name); + break; + case self::TYPE_ONLY_ITERATOR: + return new OnlyIterator(self::$$name); + break; + case self::TYPE_ARRAY_ARRAY: + default: + return self::$$name; + break; + } + } +} diff --git a/test/testing.config.php.dist b/test/testing.config.php.dist index 9c8842d..e52726a 100644 --- a/test/testing.config.php.dist +++ b/test/testing.config.php.dist @@ -28,6 +28,20 @@ return [ ], ], ], + // package name + 'universal' => [ + // container id + 'orm_default' => [ + // mandatory params + 'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver', + 'params' => [ + 'host' => 'localhost', + 'user' => 'username', + 'password' => 'password', + 'dbname' => 'database', + ], + ], + ], ], 'one' => [ 'two' => [