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

ExistsConditionTest   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 18
c 1
b 0
f 1
dl 0
loc 31
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testFromArrayDefinitionExceptionQuery() 0 5 1
A testConstructor() 0 10 1
A testFromArrayDefinition() 0 10 1
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\Connection\ConnectionInterface;
9
use Yiisoft\Db\Exception\InvalidArgumentException;
10
use Yiisoft\Db\Query\Query;
11
use Yiisoft\Db\QueryBuilder\Conditions\ExistsCondition;
12
13
/**
14
 * @group db
15
 */
16
final class ExistsConditionTest extends TestCase
17
{
18
    public function testConstructor(): void
19
    {
20
        $query = (new Query($this->createMock(ConnectionInterface::class)))
21
            ->select('id')
22
            ->from('users')
23
            ->where(['active' => 1]);
24
        $existCondition = new ExistsCondition('EXISTS', $query);
25
26
        $this->assertSame('EXISTS', $existCondition->getOperator());
27
        $this->assertSame($query, $existCondition->getQuery());
28
    }
29
30
    public function testFromArrayDefinition(): void
31
    {
32
        $query = (new Query($this->createMock(ConnectionInterface::class)))
33
            ->select('id')
34
            ->from('users')
35
            ->where(['active' => 1]);
36
        $existCondition = ExistsCondition::fromArrayDefinition('EXISTS', [$query]);
37
38
        $this->assertSame('EXISTS', $existCondition->getOperator());
39
        $this->assertSame($query, $existCondition->getQuery());
40
    }
41
42
    public function testFromArrayDefinitionExceptionQuery(): void
43
    {
44
        $this->expectException(InvalidArgumentException::class);
45
        $this->expectExceptionMessage('Sub query for EXISTS operator must be a Query object.');
46
        ExistsCondition::fromArrayDefinition('EXISTS', []);
47
    }
48
}
49