From 08c92a55821048075293618cf30e13b68e35da69 Mon Sep 17 00:00:00 2001 From: "a.shamavov" Date: Wed, 26 Feb 2025 15:35:55 +0500 Subject: [PATCH] =?UTF-8?q?tests:=20=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=20=D1=82=D0=B5=D1=81=D1=82=20=D0=B4=D0=BB=D1=8F=20?= =?UTF-8?q?=D1=84=D0=B8=D0=BB=D1=8C=D1=82=D1=80=D0=B0=D1=86=D0=B8=D0=B8=20?= =?UTF-8?q?Like?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/FilterByLikeTest.php | 129 +++++++++++++++++++++++++++++++++++++ 1 file changed, 129 insertions(+) create mode 100644 tests/FilterByLikeTest.php diff --git a/tests/FilterByLikeTest.php b/tests/FilterByLikeTest.php new file mode 100644 index 0000000..2b8eee6 --- /dev/null +++ b/tests/FilterByLikeTest.php @@ -0,0 +1,129 @@ +em->getRepository(Post::class); + + $title = 'Видеопредставление'; + $subtitle = 'Видео'; + + $post = new Post( + $title, + $this->faker->text(), + $this->faker->boolean(), + \DateTimeImmutable::createFromInterface($this->faker->dateTime()), + ); + + $post2 = new Post( + $this->faker->name(), + $this->faker->text(), + $this->faker->boolean(), + \DateTimeImmutable::createFromInterface($this->faker->dateTime()), + ); + + $this->em->persist($post); + $this->em->persist($post2); + $this->em->flush(); + + $result = $postRepository->createQueryByFilter([ + 'title' => Like::class, + ], new Request([ + HttpFilter::REQUEST_FILTER_KEY => [ + 'title' => $subtitle, + ], + ])) + ->getQuery() + ->getResult(); + + $this->assertNotEmpty($result); + $this->assertCount(1, $result); + $this->assertStringContainsString($subtitle, current($result)->title); + } + + public function testSuccessFilterLikeWithSeveralResults(): void + { + /** @var PostRepository $postRepository */ + $postRepository = $this->em->getRepository(Post::class); + + $titleFirst = 'Видеопредставление'; + $titleSecond = 'Видеомагнитофон'; + $subtitle = 'Видео'; + + $post = new Post( + $titleFirst, + $this->faker->text(), + $this->faker->boolean(), + \DateTimeImmutable::createFromInterface($this->faker->dateTime()), + ); + + $post2 = new Post( + $titleSecond, + $this->faker->text(), + $this->faker->boolean(), + \DateTimeImmutable::createFromInterface($this->faker->dateTime()), + ); + + $this->em->persist($post); + $this->em->persist($post2); + $this->em->flush(); + + $result = $postRepository->createQueryByFilter([ + 'title' => Like::class, + ], new Request([ + HttpFilter::REQUEST_FILTER_KEY => [ + 'title' => $subtitle, + ], + ])) + ->getQuery() + ->getResult(); + + $this->assertNotEmpty($result); + $this->assertCount(2, $result); + $this->assertStringContainsString($subtitle, current($result)->title); + $this->assertStringContainsString($subtitle, next($result)->title); + } + + public function testSuccessFilterLikeWithoutResults(): void + { + /** @var PostRepository $postRepository */ + $postRepository = $this->em->getRepository(Post::class); + + $title = 'Видеопредставление'; + $subtitle = 'видео'; + + $post = new Post( + $title, + $this->faker->text(), + $this->faker->boolean(), + \DateTimeImmutable::createFromInterface($this->faker->dateTime()), + ); + + $this->em->persist($post); + $this->em->flush(); + + $result = $postRepository->createQueryByFilter([ + 'title' => Like::class, + ], new Request([ + HttpFilter::REQUEST_FILTER_KEY => [ + 'title' => $subtitle, + ], + ])) + ->getQuery() + ->getResult(); + + $this->assertEmpty($result); + } +} -- GitLab