Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-7653: Add FilterParser and IsContainer criterion parser #84

Merged
merged 11 commits into from
May 16, 2024
7 changes: 7 additions & 0 deletions src/bundle/Resources/config/input_parsers.yml
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,13 @@ services:
tags:
- { name: ibexa.rest.input.parser, mediaType: application/vnd.ibexa.api.internal.criterion.UserMetadata }

Ibexa\Rest\Server\Input\Parser\Criterion\IsContainer:
parent: Ibexa\Rest\Server\Common\Parser
arguments:
$parserTools: '@Ibexa\Rest\Input\ParserTools'
tags:
- { name: ibexa.rest.input.parser, mediaType: application/vnd.ibexa.api.internal.criterion.IsContainer }

Ibexa\Rest\Server\Input\Parser\Criterion\IsUserBased:
parent: Ibexa\Rest\Server\Common\Parser
arguments:
Expand Down
37 changes: 37 additions & 0 deletions src/lib/Server/Input/Parser/Criterion/IsContainer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Rest\Server\Input\Parser\Criterion;

use Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\IsContainer as IsContainerCriterion;
use Ibexa\Contracts\Rest\Exceptions;
use Ibexa\Contracts\Rest\Input\ParsingDispatcher;
use Ibexa\Rest\Input\BaseParser;
use Ibexa\Rest\Input\ParserTools;

final class IsContainer extends BaseParser
{
private ParserTools $parserTools;

public function __construct(ParserTools $parserTools)
{
$this->parserTools = $parserTools;
}

/**
* @param array<mixed> $data
*/
public function parse(array $data, ParsingDispatcher $parsingDispatcher): IsContainerCriterion

Check failure on line 29 in src/lib/Server/Input/Parser/Criterion/IsContainer.php

View workflow job for this annotation

GitHub Actions / Unit & integration tests (7.4)

Method Ibexa\Rest\Server\Input\Parser\Criterion\IsContainer::parse() has invalid return type Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\IsContainer.

Check failure on line 29 in src/lib/Server/Input/Parser/Criterion/IsContainer.php

View workflow job for this annotation

GitHub Actions / Unit & integration tests (8.0)

Method Ibexa\Rest\Server\Input\Parser\Criterion\IsContainer::parse() has invalid return type Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\IsContainer.

Check failure on line 29 in src/lib/Server/Input/Parser/Criterion/IsContainer.php

View workflow job for this annotation

GitHub Actions / Unit & integration tests (8.2)

Method Ibexa\Rest\Server\Input\Parser\Criterion\IsContainer::parse() has invalid return type Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\IsContainer.
{
if (!array_key_exists('IsContainerCriterion', $data)) {
throw new Exceptions\Parser('Invalid <IsContainer> format');
}

return new IsContainerCriterion($this->parserTools->parseBooleanValue($data['IsContainerCriterion']));

Check failure on line 35 in src/lib/Server/Input/Parser/Criterion/IsContainer.php

View workflow job for this annotation

GitHub Actions / Unit & integration tests (7.4)

Instantiated class Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\IsContainer not found.

Check failure on line 35 in src/lib/Server/Input/Parser/Criterion/IsContainer.php

View workflow job for this annotation

GitHub Actions / Unit & integration tests (8.0)

Instantiated class Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\IsContainer not found.

Check failure on line 35 in src/lib/Server/Input/Parser/Criterion/IsContainer.php

View workflow job for this annotation

GitHub Actions / Unit & integration tests (8.2)

Instantiated class Ibexa\Contracts\Core\Repository\Values\Content\Query\Criterion\IsContainer not found.
}
}
40 changes: 40 additions & 0 deletions tests/bundle/Functional/SearchView/Criterion/IsContainerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
declare(strict_types=1);

namespace Ibexa\Tests\Bundle\Rest\Functional\SearchView\Criterion;

use Ibexa\Tests\Bundle\Rest\Functional\SearchView\SearchCriterionTestCase;

final class IsContainerTest extends SearchCriterionTestCase
{
/**
* @phpstan-return iterable<
* string,
* array{
* string,
* string,
* int,
* },
* >
*/
public function getCriteriaPayloads(): iterable
{
return [
'is container' => [
'json',
$this->buildJsonCriterionQuery('"IsContainerCriterion": true'),
10,
],
'is not container' => [
'json',
$this->buildJsonCriterionQuery('"IsContainerCriterion": false'),
2,
],
];
}
}
Loading