diff --git a/.travis.yml b/.travis.yml index b586fea..0cf082b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,20 +10,22 @@ cache: jobs: fast_finish: true - allow_failures: - - php: 'nightly' include: - name: "CI - 8.0" - php: 'nightly' + php: '8.0' + env: + - COMPOSER_FLAGS='--ignore-platform-req=php' - name: "CI - 7.4" php: '7.4' + env: + - COMPOSER_FLAGS='' before_install: - phpenv config-rm xdebug.ini || return 0 install: - composer self-update - - composer install --no-interaction --prefer-dist + - composer install --no-interaction --prefer-dist $COMPOSER_FLAGS script: - mkdir build diff --git a/composer.json b/composer.json index d0ed268..0b44ae9 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "laminas/laminas-servicemanager": "^3.4" }, "require-dev": { - "infection/infection": "^0.19.2", + "infection/infection": "^0.20", "phpstan/phpstan": "^0.12.52", "phpunit/phpunit": "^9.4", "roave/security-advisories": "dev-master", diff --git a/src/Factory/DottedAccessConfigAbstractFactory.php b/src/Factory/DottedAccessConfigAbstractFactory.php index bb3016d..23833ff 100644 --- a/src/Factory/DottedAccessConfigAbstractFactory.php +++ b/src/Factory/DottedAccessConfigAbstractFactory.php @@ -10,6 +10,7 @@ use Laminas\ServiceManager\Factory\AbstractFactoryInterface; use Shlinkio\Shlink\Config\Exception\InvalidArgumentException; +use function array_key_exists; use function array_shift; use function explode; use function is_array; @@ -57,7 +58,7 @@ private function readKeysFromArray(array $keys, $array) $key = array_shift($keys); // As soon as one of the provided keys is not found, throw an exception - if (! isset($array[$key])) { + if (! array_key_exists($key, $array)) { throw new InvalidArgumentException(sprintf( 'The key "%s" provided in the dotted notation could not be found in the array service', $key, diff --git a/test/Factory/DottedAccessConfigAbstractFactoryTest.php b/test/Factory/DottedAccessConfigAbstractFactoryTest.php index 8e8161c..8d6242f 100644 --- a/test/Factory/DottedAccessConfigAbstractFactoryTest.php +++ b/test/Factory/DottedAccessConfigAbstractFactoryTest.php @@ -47,20 +47,32 @@ public function throwsExceptionWhenFirstPartOfTheServiceIsNotRegistered(): void $this->factory->__invoke(new ServiceManager(), 'foo.bar'); } - /** @test */ - public function dottedNotationIsRecursivelyResolvedUntilLastValueIsFoundAndReturned(): void - { - $expected = 'this is the result'; - + /** + * @test + * @dataProvider provideDotValues + */ + public function dottedNotationIsRecursivelyResolvedUntilLastValueIsFoundAndReturned( + string $serviceName, + ?string $expected + ): void { $result = $this->factory->__invoke(new ServiceManager(['services' => [ 'foo' => [ - 'bar' => ['baz' => $expected], + 'bar' => [ + 'baz' => 'this is the result', + 'nullable_baz' => null, + ], ], - ]]), 'foo.bar.baz'); + ]]), $serviceName); $this->assertEquals($expected, $result); } + public function provideDotValues(): iterable + { + yield 'non-null value' => ['foo.bar.baz', 'this is the result']; + yield 'null value' => ['foo.bar.nullable_baz', null]; + } + /** @test */ public function exceptionIsThrownIfAnyStepCannotBeResolved(): void {