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

SimpleConditionTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 34
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testFromArrayDefinitionException() 0 5 1
A testFromArrayDefinition() 0 7 1
A testConstructor() 0 7 1
A testFromArrayDefinitionExceptionColumn() 0 7 1
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