Completed
Push — master ( 1e60c5...8c1e01 )
by Valentin
18s queued 16s
created

PostgresWriterTest::testIlike()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 8
nc 1
nop 0
dl 0
loc 13
rs 10
c 1
b 1
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Tests\DataGrid\QueryWriter;
6
7
use Spiral\Database\Database;
8
use Spiral\Database\Driver\Postgres\PostgresDriver;
9
use Spiral\Database\Query\SelectQuery;
10
use Spiral\DataGrid\Compiler;
11
use Spiral\DataGrid\Specification\Filter;
12
use Spiral\DataGrid\SpecificationInterface;
13
use Spiral\DataGrid\Writer\PostgresQueryWriter;
14
use Spiral\DataGrid\Writer\QueryWriter;
15
use Spiral\Tests\DataGrid\BaseTest;
16
17
class PostgresWriterTest extends BaseTest
18
{
19
    public function testIlike(): void
20
    {
21
        $select = $this->compile(
22
            $this->initQuery(),
23
            new Filter\Any(
24
                new Filter\Like('name', 'Antony'),
25
                new Filter\Postgres\ILike('email', '@example.')
26
            )
27
        );
28
29
        $this->assertEqualSQL(
30
            'SELECT * FROM "users" WHERE (("name" LIKE \'%Antony%\') OR ("email" ILIKE \'%@example.%\'))',
31
            $select
0 ignored issues
show
Bug introduced by
It seems like $select can also be of type null; however, parameter $compiled of Spiral\Tests\DataGrid\BaseTest::assertEqualSQL() does only seem to accept Spiral\Database\Query\SelectQuery, 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

31
            /** @scrutinizer ignore-type */ $select
Loading history...
32
        );
33
    }
34
35
    /**
36
     * @return SelectQuery
37
     */
38
    protected function initQuery(): SelectQuery
39
    {
40
        return (new Database('default', '', new PostgresDriver([])))->select()->from('users');
41
    }
42
43
    protected function compile($source, SpecificationInterface ...$specifications)
44
    {
45
        $compiler = new Compiler();
46
        $compiler->addWriter(new QueryWriter());
47
        $compiler->addWriter(new PostgresQueryWriter());
48
49
        return $compiler->compile($source, ...$specifications);
50
    }
51
}
52