Passed
Pull Request — master (#380)
by Wilmer
02:49
created

QueryTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 29
dl 0
loc 65
rs 10
c 1
b 0
f 0
wmc 5

5 Methods

Rating   Name   Duplication   Size   Complexity  
A testCount() 0 10 1
A testLimitOffsetWithExpression() 0 13 1
A testColumn() 0 10 1
A testOne() 0 10 1
A testExists() 0 10 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Tests\Query;
6
7
use Yiisoft\Db\Exception\NotSupportedException;
8
use Yiisoft\Db\Expression\Expression;
9
use Yiisoft\Db\Query\Query;
10
use Yiisoft\Db\Tests\AbstractQueryTest;
11
use Yiisoft\Db\Tests\Support\TestTrait;
12
13
/**
14
 * @group db
15
 */
16
final class QueryTest extends AbstractQueryTest
17
{
18
    use TestTrait;
19
20
    public function testColumn(): void
21
    {
22
        $db = $this->getConnectionWithData();
23
24
        $this->expectException(NotSupportedException::class);
25
        $this->expectExceptionMessage(
26
            'Yiisoft\Db\Tests\Support\Stubs\Command does not support internalExecute() by core-db.'
27
        );
28
29
        (new Query($db))->select('name')->from('customer')->orderBy(['id' => SORT_DESC])->column();
30
    }
31
32
    public function testCount(): void
33
    {
34
        $db = $this->getConnectionWithData();
35
36
        $this->expectException(NotSupportedException::class);
37
        $this->expectExceptionMessage(
38
            'Yiisoft\Db\Tests\Support\Stubs\Command does not support internalExecute() by core-db.'
39
        );
40
41
        (new Query($db))->from('customer')->count();
42
    }
43
44
    public function testExists(): void
45
    {
46
        $db = $this->getConnectionWithData();
47
48
        $this->expectException(NotSupportedException::class);
49
        $this->expectExceptionMessage(
50
            'Yiisoft\Db\Tests\Support\Stubs\Command does not support internalExecute() by core-db.'
51
        );
52
53
        (new Query($db))->from('customer')->where(['status' => 2])->exists();
54
    }
55
56
    public function testLimitOffsetWithExpression(): void
57
    {
58
        $db = $this->getConnectionWithData();
59
60
        $query = (new Query($db))->from('customer')->select('id')->orderBy('id');
61
        $query->limit(new Expression('1 + 1'))->offset(new Expression('1 + 0'));
62
63
        $this->expectException(NotSupportedException::class);
64
        $this->expectExceptionMessage(
65
            'Yiisoft\Db\Tests\Support\Stubs\Command does not support internalExecute() by core-db.'
66
        );
67
68
        $query->column();
69
    }
70
71
    public function testOne(): void
72
    {
73
        $db = $this->getConnectionWithData();
74
75
        $this->expectException(NotSupportedException::class);
76
        $this->expectExceptionMessage(
77
            'Yiisoft\Db\Tests\Support\Stubs\Command does not support internalExecute() by core-db.'
78
        );
79
80
        (new Query($db))->from('customer')->where(['status' => 2])->one();
81
    }
82
}
83