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

testFromArrayDefinitionExceptionColumn()   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\SimpleCondition;
10
11
/**
12
 * @group db
13
 */
14
final class SimpleConditionTest extends TestCase
15
{
16
    public function testConstructor(): void
17
    {
18
        $simpleCondition = new SimpleCondition('id', '=', 1);
19
20
        $this->assertSame('id', $simpleCondition->getColumn());
21
        $this->assertSame('=', $simpleCondition->getOperator());
22
        $this->assertSame(1, $simpleCondition->getValue());
23
    }
24
25
    public function testFromArrayDefinition(): void
26
    {
27
        $simpleCondition = SimpleCondition::fromArrayDefinition('=', ['id', 1]);
28
29
        $this->assertSame('id', $simpleCondition->getColumn());
30
        $this->assertSame('=', $simpleCondition->getOperator());
31
        $this->assertSame(1, $simpleCondition->getValue());
32
    }
33
34
    public function testFromArrayDefinitionException(): void
35
    {
36
        $this->expectException(InvalidArgumentException::class);
37
        $this->expectExceptionMessage("Operator '=' requires two operands.");
38
        SimpleCondition::fromArrayDefinition('=', []);
39
    }
40
41
    public function testFromArrayDefinitionExceptionColumn(): void
42
    {
43
        $this->expectException(InvalidArgumentException::class);
44
        $this->expectExceptionMessage(
45
            "Operator '=' requires column to be string, ExpressionInterface or QueryInterface."
46
        );
47
        SimpleCondition::fromArrayDefinition('=', [1, 1]);
48
    }
49
}
50