Passed
Pull Request — master (#14)
by Alexander
11:30
created

QueryTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 31
rs 10
c 0
b 0
f 0
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testLimitOffsetWithExpression() 0 13 1
A testQueryIndexHint() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Mysql\Tests;
6
7
use Yiisoft\Db\Querys\Query;
8
use Yiisoft\Db\Expressions\Expression;
9
use Yiisoft\Db\Tests\QueryTest as AbstractQueryTest;
10
11
class QueryTest extends AbstractQueryTest
12
{
13
    protected ?string $driverName = 'mysql';
14
15
    /**
16
     * Tests MySQL specific syntax for index hints.
17
     */
18
    public function testQueryIndexHint(): void
19
    {
20
        $query = (new Query($this->getConnection()))->from([new Expression('{{%customer}} USE INDEX (primary)')]);
21
22
        $row = $query->one();
23
24
        $this->assertArrayHasKey('id', $row);
0 ignored issues
show
Bug introduced by
It seems like $row can also be of type false; however, parameter $array of PHPUnit\Framework\Assert::assertArrayHasKey() does only seem to accept ArrayAccess|array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

24
        $this->assertArrayHasKey('id', /** @scrutinizer ignore-type */ $row);
Loading history...
25
        $this->assertArrayHasKey('name', $row);
26
        $this->assertArrayHasKey('email', $row);
27
    }
28
29
    public function testLimitOffsetWithExpression(): void
30
    {
31
        $query = (new Query($this->getConnection()))->from('customer')->select('id')->orderBy('id');
32
33
        // In MySQL limit and offset arguments must both be non negative integer constant
34
        $query->limit(new Expression('2'))->offset(new Expression('1'));
35
36
        $result = $query->column();
37
38
        $this->assertCount(2, $result);
39
        $this->assertContains("2", $result);
40
        $this->assertContains("3", $result);
41
        $this->assertNotContains("1", $result);
42
    }
43
}
44