Skip to content

Commit

Permalink
Merge pull request shlinkio#6 from acelaya-forks/feature/fix-null-opt…
Browse files Browse the repository at this point in the history
…ions

Feature/fix null options
  • Loading branch information
acelaya authored Dec 10, 2020
2 parents 78c947a + fbd14c7 commit de0616f
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 19 deletions.
10 changes: 6 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
3 changes: 2 additions & 1 deletion src/Factory/DottedAccessConfigAbstractFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions test/Collection/PathCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/ConfigProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
],
Expand Down
30 changes: 21 additions & 9 deletions test/Factory/DottedAccessConfigAbstractFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 */
Expand Down

0 comments on commit de0616f

Please sign in to comment.