Loading tests/HttpSortTest.php +57 −0 Original line number Diff line number Diff line Loading @@ -4,9 +4,11 @@ declare(strict_types=1); namespace IQDEV\Tests\Packages\DoctrineHttpFilter; use Doctrine\ORM\AbstractQuery; use IQDEV\Packages\DoctrineHttpFilter\Filter\Like; use IQDEV\Packages\DoctrineHttpFilter\HttpFilter; use IQDEV\Packages\DoctrineHttpFilter\HttpSort; use IQDEV\Tests\Packages\DoctrineHttpFilter\Entity\Comment; use IQDEV\Tests\Packages\DoctrineHttpFilter\Entity\Post; use IQDEV\Tests\Packages\DoctrineHttpFilter\Repository\PostRepository; use Symfony\Component\HttpFoundation\Request; Loading Loading @@ -165,4 +167,59 @@ class HttpSortTest extends TestCase $this->assertSame($date2, $result[0]->createdAt); $this->assertCount(2, $result); } public function testSortWithJoinTable(): void { /** @var PostRepository $postRepository */ $postRepository = $this->em->getRepository(Post::class); $author1 = 'Александр'; $author2 = 'Яков'; $post = new Post( $this->faker->name(), $this->faker->text(), $this->faker->boolean(), \DateTimeImmutable::createFromInterface($this->faker->dateTime()), ); $comment1 = new Comment( $author1, $this->faker->text(), \DateTimeImmutable::createFromInterface($this->faker->dateTime()), $post ); $comment2 = new Comment( $author1, $this->faker->text(), \DateTimeImmutable::createFromInterface($this->faker->dateTime()), $post ); $comment3 = new Comment( $author2, $this->faker->text(), \DateTimeImmutable::createFromInterface($this->faker->dateTime()), $post ); $this->em->persist($post); $this->em->persist($comment1); $this->em->persist($comment2); $this->em->persist($comment3); $this->em->flush(); $result = $postRepository->createQueryForSort( new Request([ HttpSort::REQUEST_SORT_KEY => [ 'c.author' => 'DESC', ], ]) ) ->leftJoin(Comment::class, 'c') ->select('p', 'c.author') ->getQuery() ->getResult(AbstractQuery::HYDRATE_ARRAY); $this->assertSame($author2, $result[0]['author']); } } Loading
tests/HttpSortTest.php +57 −0 Original line number Diff line number Diff line Loading @@ -4,9 +4,11 @@ declare(strict_types=1); namespace IQDEV\Tests\Packages\DoctrineHttpFilter; use Doctrine\ORM\AbstractQuery; use IQDEV\Packages\DoctrineHttpFilter\Filter\Like; use IQDEV\Packages\DoctrineHttpFilter\HttpFilter; use IQDEV\Packages\DoctrineHttpFilter\HttpSort; use IQDEV\Tests\Packages\DoctrineHttpFilter\Entity\Comment; use IQDEV\Tests\Packages\DoctrineHttpFilter\Entity\Post; use IQDEV\Tests\Packages\DoctrineHttpFilter\Repository\PostRepository; use Symfony\Component\HttpFoundation\Request; Loading Loading @@ -165,4 +167,59 @@ class HttpSortTest extends TestCase $this->assertSame($date2, $result[0]->createdAt); $this->assertCount(2, $result); } public function testSortWithJoinTable(): void { /** @var PostRepository $postRepository */ $postRepository = $this->em->getRepository(Post::class); $author1 = 'Александр'; $author2 = 'Яков'; $post = new Post( $this->faker->name(), $this->faker->text(), $this->faker->boolean(), \DateTimeImmutable::createFromInterface($this->faker->dateTime()), ); $comment1 = new Comment( $author1, $this->faker->text(), \DateTimeImmutable::createFromInterface($this->faker->dateTime()), $post ); $comment2 = new Comment( $author1, $this->faker->text(), \DateTimeImmutable::createFromInterface($this->faker->dateTime()), $post ); $comment3 = new Comment( $author2, $this->faker->text(), \DateTimeImmutable::createFromInterface($this->faker->dateTime()), $post ); $this->em->persist($post); $this->em->persist($comment1); $this->em->persist($comment2); $this->em->persist($comment3); $this->em->flush(); $result = $postRepository->createQueryForSort( new Request([ HttpSort::REQUEST_SORT_KEY => [ 'c.author' => 'DESC', ], ]) ) ->leftJoin(Comment::class, 'c') ->select('p', 'c.author') ->getQuery() ->getResult(AbstractQuery::HYDRATE_ARRAY); $this->assertSame($author2, $result[0]['author']); } }