Passed
Pull Request — master (#376)
by Wilmer
02:27
created

testFromArrayDefinitionExceptionOperandsValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 7
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Tests\QueryBuilder\Conditions;
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('BETWEEN', [42, 'min_value', 'max_value']);
29
30
        $this->assertSame(42, $betweenColumnsCondition->getValue());
31
        $this->assertSame('BETWEEN', $betweenColumnsCondition->getOperator());
32
        $this->assertSame('min_value', $betweenColumnsCondition->getIntervalStartColumn());
33
        $this->assertSame('max_value', $betweenColumnsCondition->getIntervalEndColumn());
34
    }
35
36
    public function testFromArrayDefinitionExceptionWithoutOperands(): void
37
    {
38
        $this->expectException(InvalidArgumentException::class);
39
        $this->expectExceptionMessage("Operator 'between' requires three operands.");
40
        BetweenColumnsCondition::fromArrayDefinition('between', []);
41
    }
42
43
    public function testFromArrayDefinitionExceptionOperandsValue(): void
44
    {
45
        $this->expectException(InvalidArgumentException::class);
46
        $this->expectExceptionMessage(
47
            "Operator 'between' requires value to be array, int, string, Iterator or ExpressionInterface."
48
        );
49
        BetweenColumnsCondition::fromArrayDefinition('between', [false, 'min_value', 'max_value']);
50
    }
51
52
    public function testFromArrayDefinitionExceptionOperandsIntervalStartColumn(): void
53
    {
54
        $this->expectException(InvalidArgumentException::class);
55
        $this->expectExceptionMessage(
56
            "Operator 'between' requires interval start column to be string or ExpressionInterface."
57
        );
58
        BetweenColumnsCondition::fromArrayDefinition('between', [42, false, 'max_value']);
59
    }
60
61
    public function testFromArrayDefinitionExceptionOperandsIntervalEndColumn(): void
62
    {
63
        $this->expectException(InvalidArgumentException::class);
64
        $this->expectExceptionMessage(
65
            "Operator 'between' requires interval end column to be string or ExpressionInterface."
66
        );
67
        BetweenColumnsCondition::fromArrayDefinition('between', [42, 'min_value', false]);
68
    }
69
}
70