From 9d2c2756187edb7db4a9b18a9090ffb8a2c3f69c Mon Sep 17 00:00:00 2001 From: beberlei Date: Sat, 20 Mar 2010 17:40:30 +0000 Subject: [PATCH] [2.0] DDC-407 - Add regression-test to fix that Scalar-Results are 1-based, Add ScalarResult with Scalar Field Hydration Test --- .../ORM/Functional/AdvancedDqlQueryTest.php | 13 ++++++++++ .../ORM/Hydration/ScalarHydratorTest.php | 24 +++++++++++++++++++ 2 files changed, 37 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Functional/AdvancedDqlQueryTest.php b/tests/Doctrine/Tests/ORM/Functional/AdvancedDqlQueryTest.php index a00ac185f..be75c2c1e 100644 --- a/tests/Doctrine/Tests/ORM/Functional/AdvancedDqlQueryTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/AdvancedDqlQueryTest.php @@ -39,6 +39,19 @@ class AdvancedDqlQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->assertEquals(600000, $result[1]['avgSalary']); } + public function testUnnamedScalarResultsAreOneBased() + { + $dql = 'SELECT p.department, AVG(p.salary) '. + 'FROM Doctrine\Tests\Models\Company\CompanyEmployee p '. + 'GROUP BY p.department HAVING SUM(p.salary) > 200000 ORDER BY p.department'; + + $result = $this->_em->createQuery($dql)->getScalarResult(); + + $this->assertEquals(2, count($result)); + $this->assertEquals(150000, $result[0][1]); + $this->assertEquals(600000, $result[1][1]); + } + public function testOrderByResultVariableCollectionSize() { $dql = 'SELECT p.name, size(p.friends) AS friends ' . diff --git a/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php b/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php index 6af318eba..079778a8c 100644 --- a/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php +++ b/tests/Doctrine/Tests/ORM/Hydration/ScalarHydratorTest.php @@ -44,4 +44,28 @@ class ScalarHydratorTest extends HydrationTestCase $this->assertEquals('jwage', $result[1]['u_name']); $this->assertEquals(2, $result[1]['u_id']); } + + /** + * @group DDC-407 + */ + public function testHydrateScalarResults() + { + $rsm = new ResultSetMapping(); + $rsm->addScalarResult('foo1', 'foo'); + $rsm->addScalarResult('bar2', 'bar'); + $rsm->addScalarResult('baz3', 'baz'); + + $resultSet = array( + array( + 'foo1' => 'A', + 'bar2' => 'B', + 'baz3' => 'C', + ), + ); + + $stmt = new HydratorMockStatement($resultSet); + $hydrator = new \Doctrine\ORM\Internal\Hydration\ScalarHydrator($this->_em); + + $result = $hydrator->hydrateAll($stmt, $rsm); + } } \ No newline at end of file