Skip to content

Commit 2373ce3

Browse files
alquercithePanz
authored andcommitted
fix(Query): add failed test for column added twice with custom aliases
1 parent 0df2b8b commit 2373ce3

File tree

1 file changed

+70
-0
lines changed

1 file changed

+70
-0
lines changed

tests/Ticket/585TestCase.php

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
<?php
2+
/*
3+
* $Id$
4+
*
5+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
6+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
7+
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
8+
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
9+
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
10+
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
11+
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
12+
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
13+
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
14+
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
15+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
16+
*
17+
* This software consists of voluntary contributions made by many individuals
18+
* and is licensed under the LGPL. For more information, see
19+
* <http://www.doctrine-project.org>.
20+
*/
21+
22+
class Doctrine_Ticket_585_TestCase extends Doctrine_UnitTestCase
23+
{
24+
private function doTestWithAllColumnsAliased($hydrateType, $expectedKeys)
25+
{
26+
try {
27+
$query = Doctrine_Query::create()
28+
->select('u.id as aliasId, u.name as aliasName')
29+
->from('User u')
30+
->leftJoin('u.Email e')
31+
;
32+
33+
$results = $query->execute(array(), $hydrateType);
34+
35+
$expectedSql = 'SELECT e.id AS e__0, e.name AS e__1 FROM entity e LEFT JOIN email e2 ON e.email_id = e2.id WHERE (e.type = 0)';
36+
37+
$this->assertEqual($expectedSql, $query->getSqlQuery());
38+
$this->assertEqual($expectedKeys, array_keys($results[0]));
39+
$this->assertEqual(count($this->users), count($results));
40+
41+
$this->pass();
42+
} catch (Exception $e) {
43+
$this->fail($e->getMessage());
44+
}
45+
}
46+
47+
public function test_hydrateScalar_withAllColumnsAliased_thenResultsHasAllRecords()
48+
{
49+
$hydrateType = Doctrine_Core::HYDRATE_SCALAR;
50+
$expectedKeys = array('u_aliasId', 'u_aliasName');
51+
52+
$this->doTestWithAllColumnsAliased($hydrateType, $expectedKeys);
53+
}
54+
55+
public function test_hydrateArrayShallow_withAllColumnsAliased_thenResultsHasAllRecords()
56+
{
57+
$hydrateType = Doctrine_Core::HYDRATE_ARRAY_SHALLOW;
58+
$expectedKeys = array('aliasId', 'aliasName');
59+
60+
$this->doTestWithAllColumnsAliased($hydrateType, $expectedKeys);
61+
}
62+
63+
public function test_hydrateArray_withAllColumnsAliased_thenResultsHasAllRecords()
64+
{
65+
$hydrateType = Doctrine_Core::HYDRATE_ARRAY;
66+
$expectedKeys = array('aliasId', 'aliasName');
67+
68+
$this->doTestWithAllColumnsAliased($hydrateType, $expectedKeys);
69+
}
70+
}

0 commit comments

Comments
 (0)