|
20 | 20 | use Yiisoft\Db\Expression\ExpressionInterface; |
21 | 21 | use Yiisoft\Db\Query\Query; |
22 | 22 | use Yiisoft\Db\Query\QueryInterface; |
| 23 | +use Yiisoft\Db\QueryBuilder\Condition\ArrayOverlapsCondition; |
| 24 | +use Yiisoft\Db\QueryBuilder\Condition\JsonOverlapsCondition; |
23 | 25 | use Yiisoft\Db\QueryBuilder\Condition\SimpleCondition; |
24 | 26 | use Yiisoft\Db\Schema\Builder\ColumnInterface; |
25 | 27 | use Yiisoft\Db\Schema\QuoterInterface; |
@@ -1545,6 +1547,57 @@ public function testsCreateConditionFromArray(): void |
1545 | 1547 | ); |
1546 | 1548 | } |
1547 | 1549 |
|
| 1550 | + public function testCreateOverlapsConditionFromArray(): void |
| 1551 | + { |
| 1552 | + $db = $this->getConnection(); |
| 1553 | + $qb = $db->getQueryBuilder(); |
| 1554 | +
|
| 1555 | + $condition = $qb->createConditionFromArray(['array overlaps', 'column', [1, 2, 3]]); |
| 1556 | +
|
| 1557 | + $this->assertInstanceOf(ArrayOverlapsCondition::class, $condition); |
| 1558 | + $this->assertSame('column', $condition->getColumn()); |
| 1559 | + $this->assertSame([1, 2, 3], $condition->getValues()); |
| 1560 | +
|
| 1561 | + $condition = $qb->createConditionFromArray(['json overlaps', 'column', [1, 2, 3]]); |
| 1562 | +
|
| 1563 | + $this->assertInstanceOf(JsonOverlapsCondition::class, $condition); |
| 1564 | + $this->assertSame('column', $condition->getColumn()); |
| 1565 | + $this->assertSame([1, 2, 3], $condition->getValues()); |
| 1566 | + } |
| 1567 | +
|
| 1568 | + public function testCreateOverlapsConditionFromArrayWithInvalidOperandsCount(): void |
| 1569 | + { |
| 1570 | + $db = $this->getConnection(); |
| 1571 | + $qb = $db->getQueryBuilder(); |
| 1572 | +
|
| 1573 | + $this->expectException(InvalidArgumentException::class); |
| 1574 | + $this->expectExceptionMessage('Operator "JSON OVERLAPS" requires two operands.'); |
| 1575 | +
|
| 1576 | + $qb->createConditionFromArray(['json overlaps', 'column']); |
| 1577 | + } |
| 1578 | +
|
| 1579 | + public function testCreateOverlapsConditionFromArrayWithInvalidColumn(): void |
| 1580 | + { |
| 1581 | + $db = $this->getConnection(); |
| 1582 | + $qb = $db->getQueryBuilder(); |
| 1583 | +
|
| 1584 | + $this->expectException(InvalidArgumentException::class); |
| 1585 | + $this->expectExceptionMessage('Operator "JSON OVERLAPS" requires column to be string or ExpressionInterface.'); |
| 1586 | +
|
| 1587 | + $qb->createConditionFromArray(['json overlaps', ['column'], [1, 2, 3]]); |
| 1588 | + } |
| 1589 | +
|
| 1590 | + public function testCreateOverlapsConditionFromArrayWithInvalidValues(): void |
| 1591 | + { |
| 1592 | + $db = $this->getConnection(); |
| 1593 | + $qb = $db->getQueryBuilder(); |
| 1594 | +
|
| 1595 | + $this->expectException(InvalidArgumentException::class); |
| 1596 | + $this->expectExceptionMessage('Operator "JSON OVERLAPS" requires values to be iterable or ExpressionInterface.'); |
| 1597 | +
|
| 1598 | + $qb->createConditionFromArray(['json overlaps', 'column', 1]); |
| 1599 | + } |
| 1600 | +
|
1548 | 1601 | /** |
1549 | 1602 | * @dataProvider \Yiisoft\Db\Tests\Provider\QueryBuilderProvider::createIndex |
1550 | 1603 | */ |
|
0 commit comments