Passed
Push — master ( 763c33...debe09 )
by Wilmer
29:07 queued 26:37
created

testFromArrayDefinitionExceptionColumns()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 3
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Tests\QueryBuilder\Condition;
6
7
use PHPUnit\Framework\TestCase;
8
use Yiisoft\Db\Exception\InvalidArgumentException;
9
use Yiisoft\Db\QueryBuilder\Conditions\BetweenCondition;
10
11
/**
12
 * @group db
13
 */
14
final class BetweenConditionTest extends TestCase
15
{
16
    public function testConstructor(): void
17
    {
18
        $betweenCondition = new BetweenCondition('date', 'BETWEEN', 1, 2);
19
20
        $this->assertSame('date', $betweenCondition->getColumn());
21
        $this->assertSame('BETWEEN', $betweenCondition->getOperator());
22
        $this->assertSame(1, $betweenCondition->getIntervalStart());
23
        $this->assertSame(2, $betweenCondition->getIntervalEnd());
24
    }
25
26
    public function testFromArrayDefinition(): void
27
    {
28
        $betweenCondition = BetweenCondition::fromArrayDefinition('BETWEEN', ['date', 1, 2]);
29
30
        $this->assertSame('date', $betweenCondition->getColumn());
31
        $this->assertSame('BETWEEN', $betweenCondition->getOperator());
32
        $this->assertSame(1, $betweenCondition->getIntervalStart());
33
        $this->assertSame(2, $betweenCondition->getIntervalEnd());
34
    }
35
36
    public function testFromArrayDefinitionExceptionWithoutOperands(): void
37
    {
38
        $this->expectException(InvalidArgumentException::class);
39
        $this->expectExceptionMessage("Operator 'between' requires three operands.");
40
        BetweenCondition::fromArrayDefinition('between', []);
41
    }
42
43
    public function testFromArrayDefinitionExceptionColumns(): void
44
    {
45
        $this->expectException(InvalidArgumentException::class);
46
        $this->expectExceptionMessage("Operator 'between' requires column to be string or ExpressionInterface.");
47
        BetweenCondition::fromArrayDefinition('between', [1, 'min_value', 'max_value']);
48
    }
49
}
50