From 8528756b63c11b53ff68c6ac7aa1887f16f6e6b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Mon, 14 Aug 2023 13:40:10 +0200 Subject: [PATCH 1/7] Added PHPStan --- tests/lib/Output/Generator/JsonTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/lib/Output/Generator/JsonTest.php b/tests/lib/Output/Generator/JsonTest.php index 71af8c0f1..980809387 100644 --- a/tests/lib/Output/Generator/JsonTest.php +++ b/tests/lib/Output/Generator/JsonTest.php @@ -208,6 +208,7 @@ public function testGeneratorHashElement() $generator->startHashElement('elements'); + \Phpstan\dumpType($generator); $generator->startValueElement('element', 'element value 1', ['attribute' => 'attribute value 1']); $generator->endValueElement('element'); From ea83e6cd4dc921a3fdefb84d9f0189d7fa5fa4be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Mon, 14 Aug 2023 13:44:10 +0200 Subject: [PATCH 2/7] Revert "Added PHPStan" This reverts commit 01e0752c39e5a781c143323cb75aa2d4e01eefc0. --- tests/lib/Output/Generator/JsonTest.php | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/lib/Output/Generator/JsonTest.php b/tests/lib/Output/Generator/JsonTest.php index 980809387..71af8c0f1 100644 --- a/tests/lib/Output/Generator/JsonTest.php +++ b/tests/lib/Output/Generator/JsonTest.php @@ -208,7 +208,6 @@ public function testGeneratorHashElement() $generator->startHashElement('elements'); - \Phpstan\dumpType($generator); $generator->startValueElement('element', 'element value 1', ['attribute' => 'attribute value 1']); $generator->endValueElement('element'); From e61d377f861fc3c580cacbc0795a57f63b56aa8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Mon, 20 Feb 2023 18:26:29 +0100 Subject: [PATCH 3/7] IBX-5135: Added LocationDepth criterion parser --- src/bundle/Resources/config/input_parsers.yml | 5 + .../Input/Parser/Criterion/Location/Depth.php | 84 +++++++++++ tests/bundle/Functional/JsonSchema/View.json | 136 ++++++++++++++++++ tests/bundle/Functional/ViewTest.php | 64 ++++++++- .../_input/search/LocationDepth.eq.json | 15 ++ .../_input/search/LocationDepth.eq.xml | 16 +++ .../_input/search/LocationDepth.in.json | 15 ++ .../_input/search/LocationDepth.in.xml | 17 +++ 8 files changed, 348 insertions(+), 4 deletions(-) create mode 100644 src/lib/Server/Input/Parser/Criterion/Location/Depth.php create mode 100644 tests/bundle/Functional/JsonSchema/View.json create mode 100644 tests/bundle/Functional/_input/search/LocationDepth.eq.json create mode 100644 tests/bundle/Functional/_input/search/LocationDepth.eq.xml create mode 100644 tests/bundle/Functional/_input/search/LocationDepth.in.json create mode 100644 tests/bundle/Functional/_input/search/LocationDepth.in.xml diff --git a/src/bundle/Resources/config/input_parsers.yml b/src/bundle/Resources/config/input_parsers.yml index 379a707b3..c92b93591 100644 --- a/src/bundle/Resources/config/input_parsers.yml +++ b/src/bundle/Resources/config/input_parsers.yml @@ -291,6 +291,11 @@ services: tags: - { name: ibexa.rest.input.parser, mediaType: application/vnd.ibexa.api.internal.LocationQuery } + Ibexa\Rest\Server\Input\Parser\Criterion\Location\Depth: + parent: Ibexa\Rest\Server\Common\Parser + tags: + - { name: ibexa.rest.input.parser, mediaType: application/vnd.ibexa.api.internal.criterion.LocationDepth } + Ibexa\Rest\Server\Input\Parser\Criterion\Ancestor: parent: Ibexa\Rest\Server\Common\Parser class: Ibexa\Rest\Server\Input\Parser\Criterion\Ancestor diff --git a/src/lib/Server/Input/Parser/Criterion/Location/Depth.php b/src/lib/Server/Input/Parser/Criterion/Location/Depth.php new file mode 100644 index 000000000..7660b0403 --- /dev/null +++ b/src/lib/Server/Input/Parser/Criterion/Location/Depth.php @@ -0,0 +1,84 @@ + Operator::IN, + 'EQ' => Operator::EQ, + 'GT' => Operator::GT, + 'GTE' => Operator::GTE, + 'LT' => Operator::LT, + 'LTE' => Operator::LTE, + 'BETWEEN' => Operator::BETWEEN, + ]; + + public function parse(array $data, ParsingDispatcher $parsingDispatcher): DepthCriterion + { + if (!array_key_exists('LocationDepth', $data)) { + throw new Exceptions\Parser('Invalid format'); + } + + $criterionData = $data['LocationDepth']; + if (!is_array($criterionData)) { + throw new Exceptions\Parser('Invalid format'); + } + + if (!isset($criterionData['Value'])) { + throw new Exceptions\Parser('Invalid format'); + } + + if ( + is_string($criterionData['Value']) + && is_numeric($criterionData['Value']) + && ((int)$criterionData['Value'] == $criterionData['Value']) + ) { + $criterionData['Value'] = (int)$criterionData['Value']; + } + + if (!in_array(gettype($criterionData['Value']), ['integer', 'array'], true)) { + throw new Exceptions\Parser('Invalid format'); + } + + $value = $criterionData['Value']; + + if (!isset($criterionData['Operator'])) { + throw new Exceptions\Parser('Invalid format'); + } + + $operator = $this->getOperator($criterionData['Operator']); + + return new DepthCriterion($operator, $value); + } + + /** + * Get operator for the given literal name. + */ + private function getOperator(string $operatorName): string + { + $operatorName = strtoupper($operatorName); + if (!isset(self::OPERATORS[$operatorName])) { + throw new Exceptions\Parser( + sprintf( + 'Unexpected LocationDepth operator. Expected one of: %s', + implode(', ', array_keys(self::OPERATORS)) + ) + ); + } + + return self::OPERATORS[$operatorName]; + } +} diff --git a/tests/bundle/Functional/JsonSchema/View.json b/tests/bundle/Functional/JsonSchema/View.json new file mode 100644 index 000000000..9849516e6 --- /dev/null +++ b/tests/bundle/Functional/JsonSchema/View.json @@ -0,0 +1,136 @@ +{ + "$schema": "http://json-schema.org/draft-04/schema#", + "type": "object", + "additionalProperties": false, + "required": [ + "View" + ], + "properties": { + "View": { + "type": "object", + "additionalProperties": false, + "required": [ + "_media-type", + "_href", + "identifier", + "Query", + "Result" + ], + "properties": { + "_media-type": { + "type": "string" + }, + "_href": { + "type": "string" + }, + "identifier": { + "type": "string" + }, + "Query": { + "type": "object", + "properties": { + "_media-type": { + "type": "string" + } + }, + "additionalProperties": false, + "required": [ + "_media-type" + ] + }, + "Result": { + "type": "object", + "additionalProperties": false, + "required": [ + "_media-type", + "_href", + "count", + "time", + "timedOut", + "maxScore", + "searchHits", + "aggregations" + ], + "properties": { + "_media-type": { + "type": "string" + }, + "_href": { + "type": "string" + }, + "count": { + "type": "number" + }, + "time": { + "type": "number" + }, + "timedOut": { + "type": "boolean" + }, + "maxScore": { + "oneOf": [ + { + "type": "number" + }, { + "type": "null" + } + ] + }, + "searchHits": { + "type": "object", + "additionalProperties": false, + "required": [ + "searchHit" + ], + "properties": { + "searchHit": { + "type": "array", + "items": { + "type": "object", + "required": [ + "_media-type", + "_score", + "_index", + "value" + ], + "additionalProperties": false, + "properties": { + "_media-type": { + "type": "string" + }, + "_score": { + "type": "number" + }, + "_index": { + "type": "string" + }, + "value": { + "type": "object", + "required": [ + "_media-type", + "Content" + ], + "additionalProperties": false, + "properties": { + "_media-type": { + "type": "string" + }, + "Content": { + "type": "object" + } + } + } + } + } + } + } + }, + "aggregations": { + "type": "array" + } + } + } + } + } + } +} diff --git a/tests/bundle/Functional/ViewTest.php b/tests/bundle/Functional/ViewTest.php index 0477dcacb..9df4f4c1c 100644 --- a/tests/bundle/Functional/ViewTest.php +++ b/tests/bundle/Functional/ViewTest.php @@ -8,10 +8,12 @@ class ViewTest extends TestCase { + use ResourceAssertionsTrait; + /** * Covers POST /views. */ - public function testViewRequestWithOrStatement() + public function testViewRequestWithOrStatement(): void { $fooRemoteId = md5('View test content foo'); $barRemoteId = md5('View test content bar'); @@ -42,17 +44,71 @@ public function testViewRequestWithOrStatement() $body ); $response = $this->sendHttpRequest($request); + self::assertHttpResponseCodeEquals($response, 200); + self::assertJsonResponseIsValid($response->getBody()->getContents(), 'View'); $responseData = json_decode($response->getBody(), true); self::assertEquals(2, $responseData['View']['Result']['count']); } + /** + * @dataProvider provideForViewTest + */ + public function testCriterions(string $body, string $type): void + { + $request = $this->createHttpRequest( + 'POST', + '/api/ibexa/v2/views', + "ViewInput+$type", + 'View+json', + $body + ); + $response = $this->sendHttpRequest($request); + self::assertHttpResponseCodeEquals($response, 200); + self::assertJsonResponseIsValid($response->getBody()->getContents(), 'View'); + $responseData = json_decode($response->getBody(), true); + self::assertGreaterThan(0, $responseData['View']['Result']['count']); + } + + /** + * @return iterable + */ + public function provideForViewTest(): iterable + { + $template = static fn(string $criterion, string $operator, string $format): string => sprintf( + 'Criterion: %s / Operator: %s / Format: %s', + $criterion, + strtoupper($operator), + strtoupper($format), + ); + + yield $template('LocationDepth', 'eq', 'xml') => [ + file_get_contents(__DIR__ . '/_input/search/LocationDepth.eq.xml'), + 'xml', + ]; + + yield $template('LocationDepth', 'eq', 'json') => [ + file_get_contents(__DIR__ . '/_input/search/LocationDepth.eq.json'), + 'json', + ]; + + yield $template('LocationDepth', 'in', 'xml') => [ + file_get_contents(__DIR__ . '/_input/search/LocationDepth.in.xml'), + 'xml', + ]; + + yield $template('LocationDepth', 'in', 'json') => [ + file_get_contents(__DIR__ . '/_input/search/LocationDepth.in.json'), + 'json', + ]; + } + /** * Covers POST /views. * * @depends testViewRequestWithOrStatement */ - public function testViewRequestWithAndStatement() + public function testViewRequestWithAndStatement(): void { $fooRemoteId = md5('View test content foo'); $barRemoteId = md5('View test content bar'); @@ -84,10 +140,10 @@ public function testViewRequestWithAndStatement() $body ); $response = $this->sendHttpRequest($request); + self::assertHttpResponseCodeEquals($response, 200); + self::assertJsonResponseIsValid($response->getBody()->getContents(), 'View'); $responseData = json_decode($response->getBody(), true); self::assertEquals(1, $responseData['View']['Result']['count']); } } - -class_alias(ViewTest::class, 'EzSystems\EzPlatformRestBundle\Tests\Functional\ViewTest'); diff --git a/tests/bundle/Functional/_input/search/LocationDepth.eq.json b/tests/bundle/Functional/_input/search/LocationDepth.eq.json new file mode 100644 index 000000000..2560ff9b8 --- /dev/null +++ b/tests/bundle/Functional/_input/search/LocationDepth.eq.json @@ -0,0 +1,15 @@ +{ + "ViewInput": { + "identifier": "TitleView", + "Query": { + "LocationFilter": { + "LocationDepth": { + "Value": [1], + "Operator": "eq" + } + }, + "limit": 10, + "offset": 0 + } + } +} diff --git a/tests/bundle/Functional/_input/search/LocationDepth.eq.xml b/tests/bundle/Functional/_input/search/LocationDepth.eq.xml new file mode 100644 index 000000000..33062ddad --- /dev/null +++ b/tests/bundle/Functional/_input/search/LocationDepth.eq.xml @@ -0,0 +1,16 @@ + + + TitleView + + + + eq + + 1 + + + + 10 + 0 + + diff --git a/tests/bundle/Functional/_input/search/LocationDepth.in.json b/tests/bundle/Functional/_input/search/LocationDepth.in.json new file mode 100644 index 000000000..3dbccd388 --- /dev/null +++ b/tests/bundle/Functional/_input/search/LocationDepth.in.json @@ -0,0 +1,15 @@ +{ + "ViewInput": { + "identifier": "TitleView", + "Query": { + "LocationFilter": { + "LocationDepth": { + "Value": [1, 2], + "Operator": "in" + } + }, + "limit": 10, + "offset": 0 + } + } +} diff --git a/tests/bundle/Functional/_input/search/LocationDepth.in.xml b/tests/bundle/Functional/_input/search/LocationDepth.in.xml new file mode 100644 index 000000000..aa591025f --- /dev/null +++ b/tests/bundle/Functional/_input/search/LocationDepth.in.xml @@ -0,0 +1,17 @@ + + + TitleView + + + + in + + 1 + 2 + + + + 10 + 0 + + From 2b09ba112d376ce06893c32c9d6b8015378bcab4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Mon, 20 Feb 2023 18:41:17 +0100 Subject: [PATCH 4/7] IBX-5135: Added LocationDepth criterion parser --- tests/bundle/Functional/ViewTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/bundle/Functional/ViewTest.php b/tests/bundle/Functional/ViewTest.php index 9df4f4c1c..a39b453a0 100644 --- a/tests/bundle/Functional/ViewTest.php +++ b/tests/bundle/Functional/ViewTest.php @@ -75,7 +75,7 @@ public function testCriterions(string $body, string $type): void */ public function provideForViewTest(): iterable { - $template = static fn(string $criterion, string $operator, string $format): string => sprintf( + $template = static fn (string $criterion, string $operator, string $format): string => sprintf( 'Criterion: %s / Operator: %s / Format: %s', $criterion, strtoupper($operator), From de5c24edae9a502cf833e8e14900fb5b3e70d828 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Tue, 21 Feb 2023 10:11:42 +0100 Subject: [PATCH 5/7] IBX-5135: Added IsMainLocation criterion parser --- src/bundle/Resources/config/input_parsers.yml | 5 ++++ .../Criterion/Location/IsMainLocation.php | 26 +++++++++++++++++++ tests/bundle/Functional/ViewTest.php | 10 +++++++ .../_input/search/IsMainLocation.json | 12 +++++++++ .../_input/search/IsMainLocation.xml | 11 ++++++++ 5 files changed, 64 insertions(+) create mode 100644 src/lib/Server/Input/Parser/Criterion/Location/IsMainLocation.php create mode 100644 tests/bundle/Functional/_input/search/IsMainLocation.json create mode 100644 tests/bundle/Functional/_input/search/IsMainLocation.xml diff --git a/src/bundle/Resources/config/input_parsers.yml b/src/bundle/Resources/config/input_parsers.yml index c92b93591..01ce90c8d 100644 --- a/src/bundle/Resources/config/input_parsers.yml +++ b/src/bundle/Resources/config/input_parsers.yml @@ -296,6 +296,11 @@ services: tags: - { name: ibexa.rest.input.parser, mediaType: application/vnd.ibexa.api.internal.criterion.LocationDepth } + Ibexa\Rest\Server\Input\Parser\Criterion\Location\IsMainLocation: + parent: Ibexa\Rest\Server\Common\Parser + tags: + - { name: ibexa.rest.input.parser, mediaType: application/vnd.ibexa.api.internal.criterion.IsMainLocation } + Ibexa\Rest\Server\Input\Parser\Criterion\Ancestor: parent: Ibexa\Rest\Server\Common\Parser class: Ibexa\Rest\Server\Input\Parser\Criterion\Ancestor diff --git a/src/lib/Server/Input/Parser/Criterion/Location/IsMainLocation.php b/src/lib/Server/Input/Parser/Criterion/Location/IsMainLocation.php new file mode 100644 index 000000000..200934136 --- /dev/null +++ b/src/lib/Server/Input/Parser/Criterion/Location/IsMainLocation.php @@ -0,0 +1,26 @@ + format'); + } + + return new IsMainLocationCriterion($data['IsMainLocation']); + } +} diff --git a/tests/bundle/Functional/ViewTest.php b/tests/bundle/Functional/ViewTest.php index a39b453a0..6326079f3 100644 --- a/tests/bundle/Functional/ViewTest.php +++ b/tests/bundle/Functional/ViewTest.php @@ -101,6 +101,16 @@ public function provideForViewTest(): iterable file_get_contents(__DIR__ . '/_input/search/LocationDepth.in.json'), 'json', ]; + + yield $template('IsMainLocation', 'eq', 'xml') => [ + file_get_contents(__DIR__ . '/_input/search/IsMainLocation.xml'), + 'xml', + ]; + + yield $template('IsMainLocation', 'eq', 'json') => [ + file_get_contents(__DIR__ . '/_input/search/IsMainLocation.json'), + 'json', + ]; } /** diff --git a/tests/bundle/Functional/_input/search/IsMainLocation.json b/tests/bundle/Functional/_input/search/IsMainLocation.json new file mode 100644 index 000000000..dc08dbd78 --- /dev/null +++ b/tests/bundle/Functional/_input/search/IsMainLocation.json @@ -0,0 +1,12 @@ +{ + "ViewInput": { + "identifier": "TitleView", + "Query": { + "LocationFilter": { + "IsMainLocation": 1 + }, + "limit": 10, + "offset": 0 + } + } +} diff --git a/tests/bundle/Functional/_input/search/IsMainLocation.xml b/tests/bundle/Functional/_input/search/IsMainLocation.xml new file mode 100644 index 000000000..bca5e8dae --- /dev/null +++ b/tests/bundle/Functional/_input/search/IsMainLocation.xml @@ -0,0 +1,11 @@ + + + TitleView + + + 1 + + 10 + 0 + + From fd065314ea9cf13d2c54283968d713389a5f6c12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Tue, 21 Feb 2023 13:32:10 +0100 Subject: [PATCH 6/7] Refactored --- tests/bundle/Functional/ViewTest.php | 48 +++++++++++++++++----------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/tests/bundle/Functional/ViewTest.php b/tests/bundle/Functional/ViewTest.php index 6326079f3..2d73b4481 100644 --- a/tests/bundle/Functional/ViewTest.php +++ b/tests/bundle/Functional/ViewTest.php @@ -10,6 +10,18 @@ class ViewTest extends TestCase { use ResourceAssertionsTrait; + private const VIEW_ENDPOINT_ACCEPT_TYPE = 'View+json'; + private const VIEW_ENDPOINT_URL = '/api/ibexa/v2/views'; + + private const FORMAT_XML = 'xml'; + private const FORMAT_JSON = 'json'; + + private const OPERATOR_EQUALITY = 'eq'; + private const OPERATOR_IN = 'in'; + + private const CRITERION_LOCATION_DEPTH = 'LocationDepth'; + private const CRITERION_IS_MAIN_LOCATION = 'IsMainLocation'; + /** * Covers POST /views. */ @@ -38,9 +50,9 @@ public function testViewRequestWithOrStatement(): void XML; $request = $this->createHttpRequest( 'POST', - '/api/ibexa/v2/views', + self::VIEW_ENDPOINT_URL, 'ViewInput+xml', - 'View+json', + self::VIEW_ENDPOINT_ACCEPT_TYPE, $body ); $response = $this->sendHttpRequest($request); @@ -58,9 +70,9 @@ public function testCriterions(string $body, string $type): void { $request = $this->createHttpRequest( 'POST', - '/api/ibexa/v2/views', + self::VIEW_ENDPOINT_URL, "ViewInput+$type", - 'View+json', + self::VIEW_ENDPOINT_ACCEPT_TYPE, $body ); $response = $this->sendHttpRequest($request); @@ -82,34 +94,34 @@ public function provideForViewTest(): iterable strtoupper($format), ); - yield $template('LocationDepth', 'eq', 'xml') => [ + yield $template(self::CRITERION_LOCATION_DEPTH, self::OPERATOR_EQUALITY, self::FORMAT_XML) => [ file_get_contents(__DIR__ . '/_input/search/LocationDepth.eq.xml'), - 'xml', + self::FORMAT_XML, ]; - yield $template('LocationDepth', 'eq', 'json') => [ + yield $template(self::CRITERION_LOCATION_DEPTH, self::OPERATOR_EQUALITY, self::FORMAT_JSON) => [ file_get_contents(__DIR__ . '/_input/search/LocationDepth.eq.json'), - 'json', + self::FORMAT_JSON, ]; - yield $template('LocationDepth', 'in', 'xml') => [ + yield $template(self::CRITERION_LOCATION_DEPTH, self::OPERATOR_IN, self::FORMAT_XML) => [ file_get_contents(__DIR__ . '/_input/search/LocationDepth.in.xml'), - 'xml', + self::FORMAT_XML, ]; - yield $template('LocationDepth', 'in', 'json') => [ + yield $template(self::CRITERION_LOCATION_DEPTH, self::OPERATOR_IN, self::FORMAT_JSON) => [ file_get_contents(__DIR__ . '/_input/search/LocationDepth.in.json'), - 'json', + self::FORMAT_JSON, ]; - yield $template('IsMainLocation', 'eq', 'xml') => [ + yield $template(self::CRITERION_IS_MAIN_LOCATION, self::OPERATOR_EQUALITY, self::FORMAT_XML) => [ file_get_contents(__DIR__ . '/_input/search/IsMainLocation.xml'), - 'xml', + self::FORMAT_XML, ]; - yield $template('IsMainLocation', 'eq', 'json') => [ + yield $template(self::CRITERION_IS_MAIN_LOCATION, self::OPERATOR_EQUALITY, self::FORMAT_JSON) => [ file_get_contents(__DIR__ . '/_input/search/IsMainLocation.json'), - 'json', + self::FORMAT_JSON, ]; } @@ -144,9 +156,9 @@ public function testViewRequestWithAndStatement(): void XML; $request = $this->createHttpRequest( 'POST', - '/api/ibexa/v2/views', + self::VIEW_ENDPOINT_URL, 'ViewInput+xml', - 'View+json', + self::VIEW_ENDPOINT_ACCEPT_TYPE, $body ); $response = $this->sendHttpRequest($request); From 2ad17b3a3d3d719d761a2409551fe47bcfd858d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Niedzielski?= Date: Mon, 14 Aug 2023 14:25:36 +0200 Subject: [PATCH 7/7] Added PHPStan --- phpstan-baseline.neon | 80 ---------------------------- src/contracts/Input/Parser.php | 2 +- tests/bundle/Functional/ViewTest.php | 27 +++++++--- 3 files changed, 22 insertions(+), 87 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 90264ca20..75fd68ba2 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -285,11 +285,6 @@ parameters: count: 1 path: src/contracts/Input/Handler.php - - - message: "#^Method Ibexa\\\\Contracts\\\\Rest\\\\Input\\\\Parser\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" - count: 1 - path: src/contracts/Input/Parser.php - - message: "#^Cannot access offset mixed on Ibexa\\\\Contracts\\\\Rest\\\\Input\\\\Parser\\.$#" count: 2 @@ -2165,31 +2160,16 @@ parameters: count: 1 path: src/lib/Server/Input/Parser/Aggregation/AbstractRangeAggregationParser.php - - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Aggregation\\\\AbstractRangeAggregationParser\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" - count: 1 - path: src/lib/Server/Input/Parser/Aggregation/AbstractRangeAggregationParser.php - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Aggregation\\\\AbstractRangeAggregationParser\\:\\:parseAggregation\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" count: 1 path: src/lib/Server/Input/Parser/Aggregation/AbstractRangeAggregationParser.php - - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Aggregation\\\\AbstractStatsAggregationParser\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" - count: 1 - path: src/lib/Server/Input/Parser/Aggregation/AbstractStatsAggregationParser.php - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Aggregation\\\\AbstractStatsAggregationParser\\:\\:parseAggregation\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" count: 1 path: src/lib/Server/Input/Parser/Aggregation/AbstractStatsAggregationParser.php - - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Aggregation\\\\AbstractTermAggregationParser\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" - count: 1 - path: src/lib/Server/Input/Parser/Aggregation/AbstractTermAggregationParser.php - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Aggregation\\\\AbstractTermAggregationParser\\:\\:parseAggregation\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" count: 1 @@ -2290,11 +2270,6 @@ parameters: count: 1 path: src/lib/Server/Input/Parser/Aggregation/ObjectStateTermAggregationParser.php - - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Aggregation\\\\Range\\\\AbstractRangeParser\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" - count: 1 - path: src/lib/Server/Input/Parser/Aggregation/Range/AbstractRangeParser.php - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Aggregation\\\\Range\\\\AbstractRangeParser\\:\\:visitRangeValue\\(\\) has no return type specified\\.$#" count: 1 @@ -2465,16 +2440,6 @@ parameters: count: 1 path: src/lib/Server/Input/Parser/Criterion/FullText.php - - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\IsUserBased\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" - count: 1 - path: src/lib/Server/Input/Parser/Criterion/IsUserBased.php - - - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\IsUserEnabled\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" - count: 1 - path: src/lib/Server/Input/Parser/Criterion/IsUserEnabled.php - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\LanguageCode\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" count: 1 @@ -2545,11 +2510,6 @@ parameters: count: 1 path: src/lib/Server/Input/Parser/Criterion/ObjectStateId.php - - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\ObjectStateIdentifier\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" - count: 1 - path: src/lib/Server/Input/Parser/Criterion/ObjectStateIdentifier.php - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\Operator\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" count: 1 @@ -2575,41 +2535,16 @@ parameters: count: 1 path: src/lib/Server/Input/Parser/Criterion/SectionId.php - - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\SectionIdentifier\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" - count: 1 - path: src/lib/Server/Input/Parser/Criterion/SectionIdentifier.php - - - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\Sibling\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" - count: 1 - path: src/lib/Server/Input/Parser/Criterion/Sibling.php - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\Subtree\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" count: 1 path: src/lib/Server/Input/Parser/Criterion/Subtree.php - - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\UserEmail\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" - count: 1 - path: src/lib/Server/Input/Parser/Criterion/UserEmail.php - - - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\UserId\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" - count: 1 - path: src/lib/Server/Input/Parser/Criterion/UserId.php - - message: "#^Parameter \\#1 \\$value of class Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Query\\\\Criterion\\\\UserId constructor expects array\\\\|int, array\\ given\\.$#" count: 1 path: src/lib/Server/Input/Parser/Criterion/UserId.php - - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\UserLogin\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" - count: 1 - path: src/lib/Server/Input/Parser/Criterion/UserLogin.php - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Criterion\\\\UserMetadata\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" count: 1 @@ -2680,11 +2615,6 @@ parameters: count: 1 path: src/lib/Server/Input/Parser/FieldDefinitionUpdate.php - - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\JWTInput\\:\\:parse\\(\\) has parameter \\$data with no value type specified in iterable type array\\.$#" - count: 1 - path: src/lib/Server/Input/Parser/JWTInput.php - - message: "#^Method Ibexa\\\\Rest\\\\Server\\\\Input\\\\Parser\\\\Limitation\\\\PathStringRouteBasedLimitationParser\\:\\:parseIdFromHref\\(\\) has parameter \\$limitationValue with no type specified\\.$#" count: 1 @@ -6675,16 +6605,6 @@ parameters: count: 2 path: tests/bundle/Functional/UserTest.php - - - message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Rest\\\\Functional\\\\ViewTest\\:\\:testViewRequestWithAndStatement\\(\\) has no return type specified\\.$#" - count: 1 - path: tests/bundle/Functional/ViewTest.php - - - - message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Rest\\\\Functional\\\\ViewTest\\:\\:testViewRequestWithOrStatement\\(\\) has no return type specified\\.$#" - count: 1 - path: tests/bundle/Functional/ViewTest.php - - message: "#^Method Ibexa\\\\Tests\\\\Bundle\\\\Rest\\\\RequestParser\\\\RouterTest\\:\\:getRouterMock\\(\\) should return PHPUnit\\\\Framework\\\\MockObject\\\\MockObject&Symfony\\\\Component\\\\Routing\\\\RouterInterface but returns Symfony\\\\Component\\\\Routing\\\\RouterInterface\\.$#" count: 1 diff --git a/src/contracts/Input/Parser.php b/src/contracts/Input/Parser.php index 657d6d8a5..d640afe3d 100644 --- a/src/contracts/Input/Parser.php +++ b/src/contracts/Input/Parser.php @@ -14,7 +14,7 @@ abstract class Parser /** * Parse input structure. * - * @param array $data + * @param array $data * @param \Ibexa\Contracts\Rest\Input\ParsingDispatcher $parsingDispatcher * * @return \Ibexa\Contracts\Core\Repository\Values\ValueObject|object diff --git a/tests/bundle/Functional/ViewTest.php b/tests/bundle/Functional/ViewTest.php index 2d73b4481..85199e5dd 100644 --- a/tests/bundle/Functional/ViewTest.php +++ b/tests/bundle/Functional/ViewTest.php @@ -95,36 +95,51 @@ public function provideForViewTest(): iterable ); yield $template(self::CRITERION_LOCATION_DEPTH, self::OPERATOR_EQUALITY, self::FORMAT_XML) => [ - file_get_contents(__DIR__ . '/_input/search/LocationDepth.eq.xml'), + $this->loadFile(__DIR__ . '/_input/search/LocationDepth.eq.xml'), self::FORMAT_XML, ]; yield $template(self::CRITERION_LOCATION_DEPTH, self::OPERATOR_EQUALITY, self::FORMAT_JSON) => [ - file_get_contents(__DIR__ . '/_input/search/LocationDepth.eq.json'), + $this->loadFile(__DIR__ . '/_input/search/LocationDepth.eq.json'), self::FORMAT_JSON, ]; yield $template(self::CRITERION_LOCATION_DEPTH, self::OPERATOR_IN, self::FORMAT_XML) => [ - file_get_contents(__DIR__ . '/_input/search/LocationDepth.in.xml'), + $this->loadFile(__DIR__ . '/_input/search/LocationDepth.in.xml'), self::FORMAT_XML, ]; yield $template(self::CRITERION_LOCATION_DEPTH, self::OPERATOR_IN, self::FORMAT_JSON) => [ - file_get_contents(__DIR__ . '/_input/search/LocationDepth.in.json'), + $this->loadFile(__DIR__ . '/_input/search/LocationDepth.in.json'), self::FORMAT_JSON, ]; yield $template(self::CRITERION_IS_MAIN_LOCATION, self::OPERATOR_EQUALITY, self::FORMAT_XML) => [ - file_get_contents(__DIR__ . '/_input/search/IsMainLocation.xml'), + $this->loadFile(__DIR__ . '/_input/search/IsMainLocation.xml'), self::FORMAT_XML, ]; yield $template(self::CRITERION_IS_MAIN_LOCATION, self::OPERATOR_EQUALITY, self::FORMAT_JSON) => [ - file_get_contents(__DIR__ . '/_input/search/IsMainLocation.json'), + $this->loadFile(__DIR__ . '/_input/search/IsMainLocation.json'), self::FORMAT_JSON, ]; } + private function loadFile(string $filepath): string + { + $data = file_get_contents($filepath); + + if ($data === false) { + throw new \RuntimeException(sprintf( + 'Unable to get contents for file: "%s". Ensure it exists and is readable.', + $filepath, + )); + } + + return $data; + } + + /** * Covers POST /views. *