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

testFromArrayDefinitionExceptionOperandsIntervalEndColumn()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
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\BetweenColumnsCondition;
10
11
/**
12
 * @group db
13
 */
14
final class BetweenColumnsConditionTest extends TestCase
15
{
16
    public function testConstructor(): void
17
    {
18
        $betweenColumnsCondition = new BetweenColumnsCondition(42, 'BETWEEN', 'min_value', 'max_value');
19
20
        $this->assertSame(42, $betweenColumnsCondition->getValue());
21
        $this->assertSame('BETWEEN', $betweenColumnsCondition->getOperator());
22
        $this->assertSame('min_value', $betweenColumnsCondition->getIntervalStartColumn());
23
        $this->assertSame('max_value', $betweenColumnsCondition->getIntervalEndColumn());
24
    }
25
26
    public function testFromArrayDefinition(): void
27
    {
28
        $betweenColumnsCondition = BetweenColumnsCondition::fromArrayDefinition(
29
            'BETWEEN',
30
            [42, 'min_value', 'max_value']
31
        );
32
33
        $this->assertSame(42, $betweenColumnsCondition->getValue());
34
        $this->assertSame('BETWEEN', $betweenColumnsCondition->getOperator());
35
        $this->assertSame('min_value', $betweenColumnsCondition->getIntervalStartColumn());
36
        $this->assertSame('max_value', $betweenColumnsCondition->getIntervalEndColumn());
37
    }
38
39
    public function testFromArrayDefinitionExceptionWithoutOperands(): void
40
    {
41
        $this->expectException(InvalidArgumentException::class);
42
        $this->expectExceptionMessage("Operator 'between' requires three operands.");
43
        BetweenColumnsCondition::fromArrayDefinition('between', []);
44
    }
45
46
    public function testFromArrayDefinitionExceptionOperandsValue(): void
47
    {
48
        $this->expectException(InvalidArgumentException::class);
49
        $this->expectExceptionMessage(
50
            "Operator 'between' requires value to be array, int, string, Iterator or ExpressionInterface."
51
        );
52
        BetweenColumnsCondition::fromArrayDefinition('between', [false, 'min_value', 'max_value']);
53
    }
54
55
    public function testFromArrayDefinitionExceptionOperandsIntervalStartColumn(): void
56
    {
57
        $this->expectException(InvalidArgumentException::class);
58
        $this->expectExceptionMessage(
59
            "Operator 'between' requires interval start column to be string or ExpressionInterface."
60
        );
61
        BetweenColumnsCondition::fromArrayDefinition('between', [42, false, 'max_value']);
62
    }
63
64
    public function testFromArrayDefinitionExceptionOperandsIntervalEndColumn(): void
65
    {
66
        $this->expectException(InvalidArgumentException::class);
67
        $this->expectExceptionMessage(
68
            "Operator 'between' requires interval end column to be string or ExpressionInterface."
69
        );
70
        BetweenColumnsCondition::fromArrayDefinition('between', [42, 'min_value', false]);
71
    }
72
}
73