Passed
Push — master ( 5adaea...ab4b97 )
by Alexander
01:37
created

QueryTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 22
c 1
b 0
f 0
dl 0
loc 38
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testLimitOffsetWithExpression() 0 14 1
A testUnion() 0 18 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Sqlite\Tests;
6
7
use Yiisoft\Db\Expressions\Expression;
8
use Yiisoft\Db\Querys\Query;
9
use Yiisoft\Db\Tests\QueryTest as AbstractQueryTest;
10
11
class QueryTest extends AbstractQueryTest
12
{
13
    protected ?string $driverName = 'sqlite';
14
15
    public function testUnion(): void
16
    {
17
        $db = $this->getConnection();
18
19
        $query = new Query($db);
20
21
        $query->select(['id', 'name'])
22
            ->from('item')
23
            ->union(
24
                (new Query($db))
25
                    ->select(['id', 'name'])
26
                    ->from(['category'])
27
            );
28
29
        $result = $query->all();
30
31
        $this->assertNotEmpty($result);
32
        $this->assertCount(7, $result);
33
    }
34
35
    public function testLimitOffsetWithExpression(): void
36
    {
37
        $query = (new Query($this->getConnection()))->from('customer')->select('id')->orderBy('id');
38
39
        $query
40
            ->limit(new Expression('1 + 1'))
41
            ->offset(new Expression('1 + 0'));
42
43
        $result = $query->column();
44
45
        $this->assertCount(2, $result);
46
        $this->assertContains("2", $result);
47
        $this->assertContains("3", $result);
48
        $this->assertNotContains("1", $result);
49
    }
50
}
51