From 12cf82e8968339c0ce25bba798f124fd70b399c7 Mon Sep 17 00:00:00 2001 From: "a.shamavov" Date: Mon, 3 Mar 2025 14:51:45 +0500 Subject: [PATCH] =?UTF-8?q?tests:=20=D0=94=D0=BE=D0=BF=D0=BE=D0=BB=D0=BD?= =?UTF-8?q?=D0=B8=D1=82=D0=B5=D0=BB=D1=8C=D0=BD=D1=8B=D0=B5=20=D1=82=D0=B5?= =?UTF-8?q?=D1=81=D1=82=D1=8B=20=D0=B4=D0=BB=D1=8F=20Date=20=D0=B8=20Where?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/FilterByDateTest.php | 53 +++++++++++++++++++++++++++++++++++++ tests/FilterByWhereTest.php | 18 +++++++++++++ 2 files changed, 71 insertions(+) diff --git a/tests/FilterByDateTest.php b/tests/FilterByDateTest.php index 9e01aad..5de3323 100644 --- a/tests/FilterByDateTest.php +++ b/tests/FilterByDateTest.php @@ -6,6 +6,7 @@ namespace IQDEV\Tests\Packages\DoctrineHttpFilter; use DateInterval; use DateTimeImmutable; +use IQDEV\Packages\DoctrineHttpFilter\Exception\FilterParameterValueIsNullException; use IQDEV\Packages\DoctrineHttpFilter\Filter\Date; use IQDEV\Packages\DoctrineHttpFilter\HttpFilter; use IQDEV\Tests\Packages\DoctrineHttpFilter\Entity\Post; @@ -131,4 +132,56 @@ class FilterByDateTest extends TestCase $this->assertEmpty($result); } + + public function testFilterDateWithoutParameterValue(): void + { + /** @var PostRepository $postRepository */ + $postRepository = $this->em->getRepository(Post::class); + + $this->expectException(FilterParameterValueIsNullException::class); + + $postRepository->createQueryByFilter([ + 'createdAt' => Date::class, + ], new Request([ + HttpFilter::REQUEST_FILTER_KEY => [], + ])) + ->getQuery() + ->getResult(); + } + + public function testFilterDateWithNotDateParameterValue(): void + { + /** @var PostRepository $postRepository */ + $postRepository = $this->em->getRepository(Post::class); + + $result = $postRepository->createQueryByFilter([ + 'createdAt' => Date::class, + ], new Request([ + HttpFilter::REQUEST_FILTER_KEY => [ + 'createdAt' => 'not date', + ], + ])) + ->getQuery() + ->getResult(); + + $this->assertEmpty($result); + } + + public function testFilterDateWithDifferentKey(): void + { + /** @var PostRepository $postRepository */ + $postRepository = $this->em->getRepository(Post::class); + + $this->expectException(FilterParameterValueIsNullException::class); + + $postRepository->createQueryByFilter([ + 'createdAt' => Date::class, + ], new Request([ + HttpFilter::REQUEST_FILTER_KEY => [ + 'notCreatedAt' => 'Not createdAt value' + ], + ])) + ->getQuery() + ->getResult(); + } } diff --git a/tests/FilterByWhereTest.php b/tests/FilterByWhereTest.php index bd7dd3e..003353c 100644 --- a/tests/FilterByWhereTest.php +++ b/tests/FilterByWhereTest.php @@ -127,4 +127,22 @@ class FilterByWhereTest extends TestCase ->getQuery() ->getResult(); } + + public function testFilterWhereWithDifferentKey(): void + { + /** @var PostRepository $postRepository */ + $postRepository = $this->em->getRepository(Post::class); + + $this->expectException(FilterParameterValueIsNullException::class); + + $postRepository->createQueryByFilter([ + 'title' => Where::class, + ], new Request([ + HttpFilter::REQUEST_FILTER_KEY => [ + 'notTitle' => 'Not title value' + ], + ])) + ->getQuery() + ->getResult(); + } } -- GitLab