Passed
Push — master ( 2b1785...29418c )
by Alexander
03:20
created

QueryTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 28
rs 10
c 0
b 0
f 0
wmc 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Mysql\Tests;
6
7
use Yiisoft\Db\Query\Query;
8
use Yiisoft\Db\Expression\Expression;
9
use Yiisoft\Db\Tests\QueryTest as AbstractQueryTest;
10
11
class QueryTest extends AbstractQueryTest
12
{
13
    protected ?string $driverName = 'mysql';
14
15
    public function testQueryIndexHint(): void
16
    {
17
        $query = (new Query($this->getConnection()))->from([new Expression('{{%customer}} USE INDEX (primary)')]);
18
19
        $row = $query->one();
20
21
        $this->assertArrayHasKey('id', $row);
22
        $this->assertArrayHasKey('name', $row);
23
        $this->assertArrayHasKey('email', $row);
24
    }
25
26
    public function testLimitOffsetWithExpression(): void
27
    {
28
        $query = (new Query($this->getConnection()))->from('customer')->select('id')->orderBy('id');
29
30
        // In MySQL limit and offset arguments must both be non negative integer constant
31
        $query->limit(new Expression('2'))->offset(new Expression('1'));
32
33
        $result = $query->column();
34
35
        $this->assertCount(2, $result);
36
        $this->assertContains("2", $result);
37
        $this->assertContains("3", $result);
38
        $this->assertNotContains("1", $result);
39
    }
40
}
41