Passed
Pull Request — master (#420)
by Wilmer
02:59
created

QueryTest::testCount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 10
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Tests\Query;
6
7
use Throwable;
8
use Yiisoft\Db\Exception\Exception;
9
use Yiisoft\Db\Exception\InvalidConfigException;
10
use Yiisoft\Db\Exception\NotSupportedException;
11
use Yiisoft\Db\Expression\Expression;
12
use Yiisoft\Db\Query\Query;
13
use Yiisoft\Db\Tests\AbstractQueryTest;
14
use Yiisoft\Db\Tests\Support\TestTrait;
15
16
/**
17
 * @group db
18
 *
19
 * @psalm-suppress PropertyNotSetInConstructor
20
 */
21
final class QueryTest extends AbstractQueryTest
22
{
23
    use TestTrait;
24
25
    /**
26
     * @throws Exception
27
     * @throws InvalidConfigException
28
     * @throws Throwable
29
     */
30
    public function testColumn(): void
31
    {
32
        $db = $this->getConnection(true);
33
34
        $this->expectException(NotSupportedException::class);
35
        $this->expectExceptionMessage(
36
            'Yiisoft\Db\Tests\Support\Stub\Command::internalExecute is not supported by this DBMS.'
37
        );
38
39
        (new Query($db))->select('name')->from('customer')->orderBy(['id' => SORT_DESC])->column();
40
    }
41
42
    /**
43
     * @throws Exception
44
     * @throws InvalidConfigException
45
     * @throws Throwable
46
     */
47
    public function testCount(): void
48
    {
49
        $db = $this->getConnection(true);
50
51
        $this->expectException(NotSupportedException::class);
52
        $this->expectExceptionMessage(
53
            'Yiisoft\Db\Tests\Support\Stub\Command::internalExecute is not supported by this DBMS.'
54
        );
55
56
        (new Query($db))->from('customer')->count();
57
    }
58
59
    public function testExists(): void
60
    {
61
        $db = $this->getConnection(true);
62
63
        $this->expectException(NotSupportedException::class);
64
        $this->expectExceptionMessage(
65
            'Yiisoft\Db\Tests\Support\Stub\Command::internalExecute is not supported by this DBMS.'
66
        );
67
68
        (new Query($db))->from('customer')->where(['status' => 2])->exists();
69
    }
70
71
    /**
72
     * @throws Exception
73
     * @throws InvalidConfigException
74
     * @throws Throwable
75
     */
76
    public function testLimitOffsetWithExpression(): void
77
    {
78
        $db = $this->getConnection(true);
79
80
        $query = (new Query($db))->from('customer')->select('id')->orderBy('id');
81
        $query->limit(new Expression('1 + 1'))->offset(new Expression('1 + 0'));
82
83
        $this->expectException(NotSupportedException::class);
84
        $this->expectExceptionMessage(
85
            'Yiisoft\Db\Tests\Support\Stub\Command::internalExecute is not supported by this DBMS.'
86
        );
87
88
        $query->column();
89
    }
90
91
    /**
92
     * @throws Exception
93
     * @throws InvalidConfigException
94
     * @throws Throwable
95
     */
96
    public function testOne(): void
97
    {
98
        $db = $this->getConnection(true);
99
100
        $this->expectException(NotSupportedException::class);
101
        $this->expectExceptionMessage(
102
            'Yiisoft\Db\Tests\Support\Stub\Command::internalExecute is not supported by this DBMS.'
103
        );
104
105
        (new Query($db))->from('customer')->where(['status' => 2])->one();
106
    }
107
}
108