Completed
Push — ezp-31420-merge-up ( ec14fb...141a64 )
by
unknown
40:13 queued 27:42
created

SelectDoctrineQueryTest::testSubselect()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 0
loc 19
rs 9.6333
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @copyright Copyright (C) eZ Systems AS. All rights reserved.
5
 * @license For full copyright and license information view LICENSE file distributed with this source code.
6
 */
7
namespace eZ\Publish\Core\Persistence\Doctrine\Tests;
8
9
class SelectDoctrineQueryTest extends TestCase
10
{
11 View Code Duplication
    public function testSimpleSelect()
12
    {
13
        $query = $this->handler->createSelectQuery();
14
        $query->select(
15
            'val1',
16
            'val2'
17
        )->from(
18
            'query_test'
19
        );
20
21
        $this->assertEquals('SELECT val1, val2 FROM query_test', $query->getQuery());
22
    }
23
24 View Code Duplication
    public function testSelectWithWhereClause()
25
    {
26
        $query = $this->handler->createSelectQuery();
27
        $query->select(
28
            'val1',
29
            'val2'
30
        )->from(
31
            'query_test'
32
        )->where(
33
            'foo = bar',
34
            'bar = baz'
35
        );
36
37
        $this->assertEquals(
38
            'SELECT val1, val2 FROM query_test WHERE foo = bar AND bar = baz',
39
            $query->getQuery()
40
        );
41
    }
42
43
    public function testSelectWithMultipleFromsAndJoins()
44
    {
45
        $query = $this->handler->createSelectQuery();
46
        $query->select(
47
            '*'
48
        )->from(
49
            'query_test'
50
        )->innerJoin(
51
            'query_inner',
52
            'qtid',
53
            'qiid'
54
        )->from(
55
            'second_from'
56
        )->leftJoin(
57
            'second_inner',
58
            'sfid',
59
            'siid'
60
        );
61
62
        $this->assertEquals(
63
            'SELECT * FROM query_test INNER JOIN query_inner ON qtid = qiid, second_from LEFT JOIN second_inner ON sfid = siid',
64
            $query->getQuery()
65
        );
66
    }
67
68 View Code Duplication
    public function testSelectDistinct()
69
    {
70
        $query = $this->handler->createSelectQuery();
71
        $query->selectDistinct('val1', 'val2')->from('query_test');
72
73
        $this->assertEquals('SELECT DISTINCT val1, val2 FROM query_test', $query->getQuery());
74
    }
75
76 View Code Duplication
    public function testSelectGroupByHaving()
77
    {
78
        $query = $this->handler->createSelectQuery();
79
        $query->select(
80
            '*'
81
        )->from(
82
            'query_test'
83
        )->groupBy(
84
            'id'
85
        )->having(
86
            'foo = bar'
87
        );
88
89
        $this->assertEquals('SELECT * FROM query_test GROUP BY id HAVING foo = bar', $query->getQuery());
90
    }
91
92
    public function testLimitGeneration()
93
    {
94
        $query = $this->handler->createSelectQuery();
95
        $query->select(
96
            '*'
97
        )->from(
98
            'query_test'
99
        );
100
101
        $sql = (string)$query;
102
        $query->limit(10, 10);
103
104
        $limitSql = $this->connection->getDatabasePlatform()->modifyLimitQuery($sql, 10, 10);
105
106
        $this->assertEquals($limitSql, (string)$query);
107
    }
108
109
    public function testSubselect()
110
    {
111
        $query = $this->handler->createSelectQuery();
112
113
        $subselect = $query->subSelect();
114
        $subselect->select(
115
            '*'
116
        )->from(
117
            'query_test'
118
        );
119
120
        $query->select(
121
            '*'
122
        )->from(
123
            $subselect
124
        );
125
126
        $this->assertEquals('SELECT * FROM ( SELECT * FROM query_test )', (string)$query);
127
    }
128
}
129