Completed
Pull Request — master (#8)
by Chito
01:35
created

SqliteCompilerTest::testUnion()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 32
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 8
c 1
b 1
f 0
dl 0
loc 32
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace Lampager\Cake\Test\TestCase\Database;
4
5
use Cake\Datasource\ConnectionManager;
6
use Cake\ORM\TableRegistry;
7
use Lampager\Cake\Test\TestCase\TestCase;
8
9
class SqliteCompilerTest extends TestCase
10
{
11
    public $fixtures = [
12
        'plugin.Lampager\\Cake.Posts',
13
    ];
14
15
    public function setUp()
16
    {
17
        $config = ConnectionManager::getConfig('test');
18
        $this->skipIf(strpos($config['driver'], 'Sqlite') === false, 'Not using Sqlite');
19
    }
20
21
    public function testSelect()
22
    {
23
        $posts = TableRegistry::getTableLocator()->get('Posts');
24
25
        $expected = '
26
            SELECT
27
                Posts.* AS "Posts__*"
28
            FROM
29
                posts Posts
30
            ORDER BY
31
                modified ASC
32
        ';
33
34
        $actual = $posts->find()
35
            ->select(['*'])
36
            ->orderAsc('modified')
37
            ->sql();
38
39
        $this->assertSqlEquals($expected, $actual);
40
    }
41
42
    public function testUnion()
43
    {
44
        $posts = TableRegistry::getTableLocator()->get('Posts');
45
46
        $expected = '
47
            SELECT
48
                *
49
            FROM
50
                (
51
                    SELECT
52
                        Posts.* AS "Posts__*"
53
                    FROM
54
                        posts Posts
55
                    ORDER BY
56
                        modified ASC
57
                )
58
            UNION ALL
59
            SELECT
60
                *
61
            FROM
62
                (
63
                    DATETIME(\'now\')
64
                )
65
        ';
66
67
        $actual = $posts->find()
68
            ->select(['*'])
69
            ->orderAsc('modified')
70
            ->unionAll($posts->query()->func()->now())
0 ignored issues
show
Bug introduced by
$posts->query()->func()->now() of type Cake\Database\Expression\FunctionExpression is incompatible with the type Cake\Database\Query|string expected by parameter $query of Cake\Database\Query::unionAll(). ( Ignorable by Annotation )

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

70
            ->unionAll(/** @scrutinizer ignore-type */ $posts->query()->func()->now())
Loading history...
71
            ->sql();
72
73
        $this->assertSqlEquals($expected, $actual);
74
    }
75
}
76