From 51e56f900412bdec5be317f1cf98530071014cd1 Mon Sep 17 00:00:00 2001 From: Maxcastel Date: Thu, 29 Jan 2026 11:53:26 +0100 Subject: [PATCH] test: cover exception if property is null for filters --- tests/Fixtures/TestBundle/Document/Chicken.php | 3 +++ tests/Fixtures/TestBundle/Entity/Chicken.php | 3 +++ tests/Functional/Parameters/ExactFilterTest.php | 15 +++++++++++++++ tests/Functional/Parameters/IriFilterTest.php | 15 +++++++++++++++ .../Parameters/PartialSearchFilterTest.php | 15 +++++++++++++++ 5 files changed, 51 insertions(+) diff --git a/tests/Fixtures/TestBundle/Document/Chicken.php b/tests/Fixtures/TestBundle/Document/Chicken.php index 2fe846ecae3..4847072ea89 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 f3533f59801..c85f7e1dffe 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 6bc416c65e1..1cf4ced1407 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 d0c12161952..2acb79c16f9 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 b71d6c8d531..5a83d156c21 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