From 70b8b9dee0a687f78348fe975755b3a2ec296be3 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Sat, 29 Jun 2024 16:40:20 +0700 Subject: [PATCH] Improve tests --- tests/QueryBuilderTest.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/QueryBuilderTest.php b/tests/QueryBuilderTest.php index 45027a42..44145585 100644 --- a/tests/QueryBuilderTest.php +++ b/tests/QueryBuilderTest.php @@ -9,6 +9,7 @@ use Yiisoft\Db\Exception\InvalidArgumentException; use Yiisoft\Db\Exception\InvalidConfigException; use Yiisoft\Db\Exception\NotSupportedException; +use Yiisoft\Db\Expression\Expression; use Yiisoft\Db\Expression\ExpressionInterface; use Yiisoft\Db\Expression\JsonExpression; use Yiisoft\Db\Query\Query; @@ -792,11 +793,21 @@ public function testJsonOverlapsConditionBuilder(): void ); $this->assertSame([':qp0' => '[1,2,3]'], $params); + // Test column as Expression + $params = []; + $sql = $qb->buildExpression(new JsonOverlapsCondition(new Expression('column'), [1, 2, 3]), $params); + + $this->assertSame( + 'EXISTS(SELECT value FROM json_each(column) INTERSECT SELECT value FROM json_each(:qp0))=1', + $sql + ); + $this->assertSame([':qp0' => '[1,2,3]'], $params); + $db->close(); } /** @dataProvider \Yiisoft\Db\Sqlite\Tests\Provider\QueryBuilderProvider::overlapsCondition */ - public function testOverlapsCondition(iterable|ExpressionInterface $values, int $expectedCount): void + public function testJsonOverlapsCondition(iterable|ExpressionInterface $values, int $expectedCount): void { $db = $this->getConnection(true); @@ -811,7 +822,7 @@ public function testOverlapsCondition(iterable|ExpressionInterface $values, int } /** @dataProvider \Yiisoft\Db\Sqlite\Tests\Provider\QueryBuilderProvider::overlapsCondition */ - public function testOverlapsConditionOperator(iterable|ExpressionInterface $values, int $expectedCount): void + public function testJsonOverlapsConditionOperator(iterable|ExpressionInterface $values, int $expectedCount): void { $db = $this->getConnection(true);