diff --git a/tests/Fixtures/TestBundle/Document/Chicken.php b/tests/Fixtures/TestBundle/Document/Chicken.php index 2fe846ecae..4847072ea8 100644 --- a/tests/Fixtures/TestBundle/Document/Chicken.php +++ b/tests/Fixtures/TestBundle/Document/Chicken.php @@ -27,12 +27,15 @@ normalizationContext: ['hydra_prefix' => false], parameters: [ 'chickenCoop' => new QueryParameter(filter: new IriFilter()), + 'chickenCoopNoProperty' => new QueryParameter(filter: new IriFilter()), 'chickenCoopId' => new QueryParameter(filter: new ExactFilter(), property: 'chickenCoop'), 'name' => new QueryParameter(filter: new ExactFilter()), + 'nameExactNoProperty' => new QueryParameter(filter: new ExactFilter()), 'namePartial' => new QueryParameter( filter: new PartialSearchFilter(), property: 'name', ), + 'namePartialNoProperty' => new QueryParameter(filter: new PartialSearchFilter()), 'autocomplete' => new QueryParameter(filter: new FreeTextQueryFilter(new OrFilter(new ExactFilter())), properties: ['name', 'ean']), 'q' => new QueryParameter(filter: new FreeTextQueryFilter(new PartialSearchFilter()), properties: ['name', 'ean']), ], diff --git a/tests/Fixtures/TestBundle/Entity/Chicken.php b/tests/Fixtures/TestBundle/Entity/Chicken.php index f3533f5980..c85f7e1dff 100644 --- a/tests/Fixtures/TestBundle/Entity/Chicken.php +++ b/tests/Fixtures/TestBundle/Entity/Chicken.php @@ -27,12 +27,15 @@ normalizationContext: ['hydra_prefix' => false], parameters: [ 'chickenCoop' => new QueryParameter(filter: new IriFilter()), + 'chickenCoopNoProperty' => new QueryParameter(filter: new IriFilter()), 'chickenCoopId' => new QueryParameter(filter: new ExactFilter(), property: 'chickenCoop'), 'name' => new QueryParameter(filter: new ExactFilter()), + 'nameExactNoProperty' => new QueryParameter(filter: new ExactFilter()), 'namePartial' => new QueryParameter( filter: new PartialSearchFilter(), property: 'name', ), + 'namePartialNoProperty' => new QueryParameter(filter: new PartialSearchFilter()), 'autocomplete' => new QueryParameter(filter: new FreeTextQueryFilter(new OrFilter(new ExactFilter())), properties: ['name', 'ean']), 'q' => new QueryParameter(filter: new FreeTextQueryFilter(new PartialSearchFilter()), properties: ['name', 'ean']), ], diff --git a/tests/Functional/Parameters/ExactFilterTest.php b/tests/Functional/Parameters/ExactFilterTest.php index 6bc416c65e..1cf4ced140 100644 --- a/tests/Functional/Parameters/ExactFilterTest.php +++ b/tests/Functional/Parameters/ExactFilterTest.php @@ -105,6 +105,21 @@ public static function exactSearchFilterProvider(): \Generator ]; } + public function testExactSearchFilterThrowsExceptionWhenPropertyIsMissing(): void + { + $response = self::createClient()->request('GET', '/chickens?nameExactNoProperty=Gertrude'); + $this->assertResponseStatusCodeSame(400); + + $responseData = $response->toArray(false); + + $this->assertSame('An error occurred', $responseData['hydra:title']); + $this->assertSame($responseData['hydra:description'], $responseData['detail']); + $this->assertStringContainsString( + 'The filter parameter with key "nameExactNoProperty" must specify a property', + $responseData['detail'] + ); + } + /** * @throws \Throwable * @throws MongoDBException diff --git a/tests/Functional/Parameters/IriFilterTest.php b/tests/Functional/Parameters/IriFilterTest.php index d0c1216195..2acb79c16f 100644 --- a/tests/Functional/Parameters/IriFilterTest.php +++ b/tests/Functional/Parameters/IriFilterTest.php @@ -56,6 +56,21 @@ public function testIriFilterMultiple(): void $this->assertCount(2, $res['member']); } + public function testIriFilterThrowsExceptionWhenPropertyIsMissing(): void + { + $response = self::createClient()->request('GET', '/chickens?chickenCoopNoProperty=/chicken_coops/1'); + $this->assertResponseStatusCodeSame(400); + + $responseData = $response->toArray(false); + + $this->assertSame('An error occurred', $responseData['hydra:title']); + $this->assertSame($responseData['hydra:description'], $responseData['detail']); + $this->assertStringContainsString( + 'The filter parameter with key "chickenCoopNoProperty" must specify a property', + $responseData['detail'] + ); + } + /** * @throws \Throwable */ diff --git a/tests/Functional/Parameters/PartialSearchFilterTest.php b/tests/Functional/Parameters/PartialSearchFilterTest.php index b71d6c8d53..5a83d156c2 100644 --- a/tests/Functional/Parameters/PartialSearchFilterTest.php +++ b/tests/Functional/Parameters/PartialSearchFilterTest.php @@ -178,6 +178,21 @@ public static function partialSearchMultiByteFilterProvider(): \Generator ]; } + public function testPartialSearchFilterThrowsExceptionWhenPropertyIsMissing(): void + { + $response = self::createClient()->request('GET', '/chickens?namePartialNoProperty=ertrude'); + $this->assertResponseStatusCodeSame(400); + + $responseData = $response->toArray(false); + + $this->assertSame('An error occurred', $responseData['hydra:title']); + $this->assertSame($responseData['hydra:description'], $responseData['detail']); + $this->assertStringContainsString( + 'The filter parameter with key "namePartialNoProperty" must specify a property', + $responseData['detail'] + ); + } + /** * @throws \Throwable * @throws MongoDBException