Skip to content

Commit

Permalink
Close #243
Browse files Browse the repository at this point in the history
Co-authored-by: neomerx <info@neomerx.com>
  • Loading branch information
efinder2 and neomerx authored Mar 3, 2020
1 parent ee9c9f6 commit 0e45254
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/Http/Query/BaseQueryParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class BaseQueryParser implements BaseQueryParserInterface
use BaseQueryParserTrait {
BaseQueryParserTrait::getFields as getFieldsImpl;
BaseQueryParserTrait::getIncludes as getIncludesImpl;
BaseQueryParserTrait::getIncludePaths as getIncludePathsImpl;
BaseQueryParserTrait::getSorts as getSortsImpl;
BaseQueryParserTrait::getProfileUrls as getProfileUrlsImpl;
}
Expand Down Expand Up @@ -70,6 +71,14 @@ public function getIncludes(): iterable
return $this->getIncludesImpl($this->getParameters(), $this->getMessage(static::MSG_ERR_INVALID_PARAMETER));
}

/**
* @inheritdoc
*/
public function getIncludePaths(): iterable
{
return $this->getIncludePathsImpl($this->getParameters(), $this->getMessage(static::MSG_ERR_INVALID_PARAMETER));
}

/**
* @inheritdoc
*/
Expand Down
15 changes: 15 additions & 0 deletions src/Http/Query/BaseQueryParserTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,21 @@ protected function getIncludes(array $parameters, string $errorTitle): iterable
}
}

/**
* @param array $parameters
* @param string $errorTitle
*
* @return iterable
*/
protected function getIncludePaths(array $parameters, string $errorTitle): iterable
{
$aIncludes = $this->getIncludes($parameters, $errorTitle);
foreach ($aIncludes as $path => $parsed) {
\assert($parsed !== null);
yield $path;
}
}

/**
* @param array $parameters
* @param string $errorTitle
Expand Down
20 changes: 20 additions & 0 deletions tests/Http/Query/BaseQueryParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,26 @@ public function testIncludes(): void
);
}

/**
* Test query.
*/
public function testIncludePaths(): void
{
$queryParameters = [
BaseQueryParser::PARAM_INCLUDE => 'comments, comments.author',
];

$parser = $this->createParser($queryParameters);

self::assertEquals(
[
'comments',
'comments.author',
],
$this->iterableToArray($parser->getIncludePaths())
);
}

/**
* That's a special case to test possible issues with `empty` function which thinks "0" is an empty string.
*/
Expand Down

0 comments on commit 0e45254

Please sign in to comment.