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/CHANGELOG.md b/CHANGELOG.md index f5b63c6..7644f68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org). +## [1.1.1] - 2020-11-10 +### Added +* *Nothing* + +### Changed +* *Nothing* + +### Deprecated +* *Nothing* + +### Removed +* *Nothing* + +### Fixed +* Fixed `DottedAccessConfigAbstractFactory` not resolving null values that are explicitly defined. + + ## [1.1.0] - 2020-11-01 ### Added * *Nothing* 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/Collection/PathCollectionTest.php b/test/Collection/PathCollectionTest.php index ff9bafd..4081d51 100644 --- a/test/Collection/PathCollectionTest.php +++ b/test/Collection/PathCollectionTest.php @@ -32,7 +32,7 @@ public function setUp(): void */ public function pathExistsReturnsExpectedValue(array $path, bool $expected): void { - $this->assertEquals($expected, $this->collection->pathExists($path)); + self::assertEquals($expected, $this->collection->pathExists($path)); } public function providePaths(): iterable @@ -54,7 +54,7 @@ public function providePaths(): iterable */ public function getValueInPathReturnsExpectedValue(array $path, $expected): void { - $this->assertEquals($expected, $this->collection->getValueInPath($path)); + self::assertEquals($expected, $this->collection->getValueInPath($path)); } public function providePathsWithValue(): iterable diff --git a/test/ConfigProviderTest.php b/test/ConfigProviderTest.php index 124722b..f14a9f8 100644 --- a/test/ConfigProviderTest.php +++ b/test/ConfigProviderTest.php @@ -21,8 +21,8 @@ public function setUp(): void public function configIsReturned(): void { $config = ($this->configProvider)(); - $this->assertArrayHasKey('dependencies', $config); - $this->assertEquals([ + self::assertArrayHasKey('dependencies', $config); + self::assertEquals([ 'abstract_factories' => [ DottedAccessConfigAbstractFactory::class, ], diff --git a/test/Factory/DottedAccessConfigAbstractFactoryTest.php b/test/Factory/DottedAccessConfigAbstractFactoryTest.php index 8e8161c..784cc57 100644 --- a/test/Factory/DottedAccessConfigAbstractFactoryTest.php +++ b/test/Factory/DottedAccessConfigAbstractFactoryTest.php @@ -25,7 +25,7 @@ public function setUp(): void */ public function canCreateOnlyServicesWithDot(string $serviceName, bool $canCreate): void { - $this->assertEquals($canCreate, $this->factory->canCreate(new ServiceManager(), $serviceName)); + self::assertEquals($canCreate, $this->factory->canCreate(new ServiceManager(), $serviceName)); } public function provideDotNames(): iterable @@ -47,18 +47,30 @@ 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); + self::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 */