Completed
Pull Request — 2.7 (#8012)
by Stefan
08:57
created

GH8011Test   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 124
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 9
eloc 65
c 2
b 0
f 2
dl 0
loc 124
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A testOrderWithArithmeticExpressionWithLiteralAndResultVariable() 0 12 1
A testOrderWithArithmeticExpressionWithLiteralAndSingleValuedPathExpression() 0 12 1
A setUp() 0 6 1
A testOrderWithArithmeticExpressionWithResultVariableAndLiteral() 0 12 1
A generateFixture() 0 16 1
A testOrderWithArithmeticExpressionWithSingleValuedPathExpressionAndResultVariable() 0 12 1
A testOrderWithArithmeticExpressionWithResultVariableAndSingleValuedPathExpression() 0 12 1
A testOrderWithArithmeticExpressionWithSingleValuedPathExpression() 0 12 1
A testOrderWithArithmeticExpressionWithSingleValuedPathExpressionAndLiteral() 0 12 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\ORM\Functional;
6
7
use Doctrine\Tests\Models\Company\CompanyEmployee;
8
use Doctrine\Tests\OrmFunctionalTestCase;
9
10
/**
11
 * Functional tests for ordering with arithmetic expression.
12
 *
13
 * @group GH8011
14
 */
15
class GH8011Test extends OrmFunctionalTestCase
16
{
17
    protected function setUp()
18
    {
19
        $this->useModelSet('company');
20
        parent::setUp();
21
22
        $this->generateFixture();
23
    }
24
25
    public function testOrderWithArithmeticExpressionWithSingleValuedPathExpression()
26
    {
27
        $dql = 'SELECT p ' .
28
            'FROM Doctrine\Tests\Models\Company\CompanyEmployee p ' .
29
            'ORDER BY p.id + p.id ASC';
30
31
        /** @var CompanyEmployee[] $result */
32
        $result = $this->_em->createQuery($dql)->getResult();
33
34
        $this->assertEquals(2, count($result));
35
        $this->assertEquals('Benjamin E.', $result[0]->getName());
36
        $this->assertEquals('Guilherme B.', $result[1]->getName());
37
    }
38
39
    public function testOrderWithArithmeticExpressionWithLiteralAndSingleValuedPathExpression()
40
    {
41
        $dql = 'SELECT p ' .
42
            'FROM Doctrine\Tests\Models\Company\CompanyEmployee p ' .
43
            'ORDER BY 1 + p.id ASC';
44
45
        /** @var CompanyEmployee[] $result */
46
        $result = $this->_em->createQuery($dql)->getResult();
47
48
        $this->assertEquals(2, count($result));
49
        $this->assertEquals('Benjamin E.', $result[0]->getName());
50
        $this->assertEquals('Guilherme B.', $result[1]->getName());
51
    }
52
53
    public function testOrderWithArithmeticExpressionWithSingleValuedPathExpressionAndLiteral()
54
    {
55
        $dql = 'SELECT p ' .
56
            'FROM Doctrine\Tests\Models\Company\CompanyEmployee p ' .
57
            'ORDER BY p.id + 1 ASC';
58
59
        /** @var CompanyEmployee[] $result */
60
        $result = $this->_em->createQuery($dql)->getResult();
61
62
        $this->assertEquals(2, count($result));
63
        $this->assertEquals('Benjamin E.', $result[0]->getName());
64
        $this->assertEquals('Guilherme B.', $result[1]->getName());
65
    }
66
67
    public function testOrderWithArithmeticExpressionWithResultVariableAndLiteral()
68
    {
69
        $dql = 'SELECT p,  p.salary AS HIDDEN s ' .
70
            'FROM Doctrine\Tests\Models\Company\CompanyEmployee p ' .
71
            'ORDER BY s + 1 DESC';
72
73
        /** @var CompanyEmployee[] $result */
74
        $result = $this->_em->createQuery($dql)->getResult();
75
76
        $this->assertEquals(2, count($result));
77
        $this->assertEquals('Guilherme B.', $result[0]->getName());
78
        $this->assertEquals('Benjamin E.', $result[1]->getName());
79
    }
80
81
    public function testOrderWithArithmeticExpressionWithLiteralAndResultVariable()
82
    {
83
        $dql = 'SELECT p,  p.salary AS HIDDEN s ' .
84
            'FROM Doctrine\Tests\Models\Company\CompanyEmployee p ' .
85
            'ORDER BY 1 + s DESC';
86
87
        /** @var CompanyEmployee[] $result */
88
        $result = $this->_em->createQuery($dql)->getResult();
89
90
        $this->assertEquals(2, count($result));
91
        $this->assertEquals('Guilherme B.', $result[0]->getName());
92
        $this->assertEquals('Benjamin E.', $result[1]->getName());
93
    }
94
95
    public function testOrderWithArithmeticExpressionWithResultVariableAndSingleValuedPathExpression()
96
    {
97
        $dql = 'SELECT p,  p.salary AS HIDDEN s ' .
98
            'FROM Doctrine\Tests\Models\Company\CompanyEmployee p ' .
99
            'ORDER BY s + p.id DESC';
100
101
        /** @var CompanyEmployee[] $result */
102
        $result = $this->_em->createQuery($dql)->getResult();
103
104
        $this->assertEquals(2, count($result));
105
        $this->assertEquals('Guilherme B.', $result[0]->getName());
106
        $this->assertEquals('Benjamin E.', $result[1]->getName());
107
    }
108
109
    public function testOrderWithArithmeticExpressionWithSingleValuedPathExpressionAndResultVariable()
110
    {
111
        $dql = 'SELECT p,  p.salary AS HIDDEN s ' .
112
            'FROM Doctrine\Tests\Models\Company\CompanyEmployee p ' .
113
            'ORDER BY p.id + s DESC';
114
115
        /** @var CompanyEmployee[] $result */
116
        $result = $this->_em->createQuery($dql)->getResult();
117
118
        $this->assertEquals(2, count($result));
119
        $this->assertEquals('Guilherme B.', $result[0]->getName());
120
        $this->assertEquals('Benjamin E.', $result[1]->getName());
121
    }
122
123
    public function generateFixture()
124
    {
125
        $person1 = new CompanyEmployee();
126
        $person1->setName('Benjamin E.');
127
        $person1->setDepartment('IT');
128
        $person1->setSalary(200000);
129
130
        $person2 = new CompanyEmployee();
131
        $person2->setName('Guilherme B.');
132
        $person2->setDepartment('IT2');
133
        $person2->setSalary(400000);
134
135
        $this->_em->persist($person1);
136
        $this->_em->persist($person2);
137
        $this->_em->flush();
138
        $this->_em->clear();
139
    }
140
}
141