1
0
mirror of synced 2024-12-13 22:56:04 +03:00

Fixed missing changes.

This commit is contained in:
Guilherme Blanco 2011-11-03 02:37:54 -02:00
parent d1bfd57fd9
commit 058242fa27
2 changed files with 149 additions and 90 deletions

View File

@ -22,7 +22,7 @@ class CustomHydratorTest extends HydrationTestCase
class CustomHydrator extends AbstractHydrator class CustomHydrator extends AbstractHydrator
{ {
protected function _hydrateAll() protected function hydrateAllData()
{ {
return $this->_stmt->fetchAll(PDO::FETCH_ASSOC); return $this->_stmt->fetchAll(PDO::FETCH_ASSOC);
} }

View File

@ -16,9 +16,10 @@ require_once __DIR__ . '/../../TestInit.php';
class ObjectHydratorTest extends HydrationTestCase class ObjectHydratorTest extends HydrationTestCase
{ {
/** /**
* SELECT PARTIAL u.{id,name} FROM \Doctrine\Tests\Models\CMS\CmsUser u * SELECT PARTIAL u.{id,name}
* FROM Doctrine\Tests\Models\CMS\CmsUser u
*/ */
public function testSimpleEntityQuery() public function testSimpleEntityScalarFieldsQuery()
{ {
$rsm = new ResultSetMapping; $rsm = new ResultSetMapping;
$rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u'); $rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u');
@ -37,15 +38,15 @@ class ObjectHydratorTest extends HydrationTestCase
) )
); );
$stmt = new HydratorMockStatement($resultSet); $stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
$result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true));
$this->assertEquals(2, count($result)); $this->assertEquals(2, count($result));
$this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0]); $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0]);
$this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[1]); $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[1]);
$this->assertEquals(1, $result[0]->id); $this->assertEquals(1, $result[0]->id);
$this->assertEquals('romanb', $result[0]->name); $this->assertEquals('romanb', $result[0]->name);
$this->assertEquals(2, $result[1]->id); $this->assertEquals(2, $result[1]->id);
@ -53,8 +54,10 @@ class ObjectHydratorTest extends HydrationTestCase
} }
/** /**
* SELECT PARTIAL u.{id,name}
* FROM Doctrine\Tests\Models\CMS\CmsUser u
*
* @group DDC-644 * @group DDC-644
* SELECT PARTIAL u.{id,name} FROM \Doctrine\Tests\Models\CMS\CmsUser u
*/ */
public function testSkipUnknownColumns() public function testSkipUnknownColumns()
{ {
@ -74,15 +77,55 @@ class ObjectHydratorTest extends HydrationTestCase
$stmt = new HydratorMockStatement($resultSet); $stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
$result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true));
$this->assertEquals(1, count($result)); $this->assertEquals(1, count($result));
} }
/** /**
* SELECT PARTIAL u.{id,name}, PARTIAL a.{id,topic} * SELECT u.id,
* FROM \Doctrine\Tests\Models\CMS\CmsUser u, \Doctrine\Tests\Models\CMS\CmsArticle a * u.name
* FROM Doctrine\Tests\Models\CMS\CmsUser u
*/
public function testScalarQueryWithoutResultVariables()
{
$rsm = new ResultSetMapping;
$rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u');
$rsm->addScalarResult('sclr0', 'id');
$rsm->addScalarResult('sclr1', 'name');
// Faked result set
$resultSet = array(
array(
'sclr0' => '1',
'sclr1' => 'romanb'
),
array(
'sclr0' => '2',
'sclr1' => 'jwage'
)
);
$stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
$result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true));
$this->assertEquals(2, count($result));
$this->assertInternalType('array', $result[0]);
$this->assertInternalType('array', $result[1]);
$this->assertEquals(1, $result[0]['id']);
$this->assertEquals('romanb', $result[0]['name']);
$this->assertEquals(2, $result[1]['id']);
$this->assertEquals('jwage', $result[1]['name']);
}
/**
* SELECT PARTIAL u.{id, name}
* PARTIAL a.{id, topic}
* FROM Doctrine\Tests\Models\CMS\CmsUser u,
* Doctrine\Tests\Models\CMS\CmsArticle a
*/ */
public function testSimpleMultipleRootEntityQuery() public function testSimpleMultipleRootEntityQuery()
{ {
@ -110,10 +153,8 @@ class ObjectHydratorTest extends HydrationTestCase
) )
); );
$stmt = new HydratorMockStatement($resultSet); $stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
$result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true));
$this->assertEquals(4, count($result)); $this->assertEquals(4, count($result));
@ -134,7 +175,8 @@ class ObjectHydratorTest extends HydrationTestCase
} }
/** /**
* SELECT p FROM \Doctrine\Tests\Models\ECommerce\ECommerceProduct p * SELECT p
* FROM Doctrine\Tests\Models\ECommerce\ECommerceProduct p
*/ */
public function testCreatesProxyForLazyLoadingWithForeignKeys() public function testCreatesProxyForLazyLoadingWithForeignKeys()
{ {
@ -159,8 +201,7 @@ class ObjectHydratorTest extends HydrationTestCase
$proxyFactory = $this->getMock('Doctrine\ORM\Proxy\ProxyFactory', array('getProxy'), array(), '', false, false, false); $proxyFactory = $this->getMock('Doctrine\ORM\Proxy\ProxyFactory', array('getProxy'), array(), '', false, false, false);
$proxyFactory->expects($this->once()) $proxyFactory->expects($this->once())
->method('getProxy') ->method('getProxy')
->with($this->equalTo('Doctrine\Tests\Models\ECommerce\ECommerceShipping'), ->with($this->equalTo('Doctrine\Tests\Models\ECommerce\ECommerceShipping'), array('id' => 42))
array('id' => 42))
->will($this->returnValue($proxyInstance)); ->will($this->returnValue($proxyInstance));
$this->_em->setProxyFactory($proxyFactory); $this->_em->setProxyFactory($proxyFactory);
@ -171,15 +212,19 @@ class ObjectHydratorTest extends HydrationTestCase
$stmt = new HydratorMockStatement($resultSet); $stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
$result = $hydrator->hydrateAll($stmt, $rsm); $result = $hydrator->hydrateAll($stmt, $rsm);
$this->assertEquals(1, count($result)); $this->assertEquals(1, count($result));
$this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $result[0]); $this->assertInstanceOf('Doctrine\Tests\Models\ECommerce\ECommerceProduct', $result[0]);
} }
/** /**
* select u, p, upper(u.name) nameUpper from User u JOIN u.phonenumbers p * SELECT PARTIAL u.{id, status},
* PARTIAL p.{phonenumber},
* UPPER(u.name) nameUpper
* FROM User u
* JOIN u.phonenumbers p
*/ */
public function testMixedQueryFetchJoin() public function testMixedQueryFetchJoin()
{ {
@ -193,8 +238,8 @@ class ObjectHydratorTest extends HydrationTestCase
); );
$rsm->addFieldResult('u', 'u__id', 'id'); $rsm->addFieldResult('u', 'u__id', 'id');
$rsm->addFieldResult('u', 'u__status', 'status'); $rsm->addFieldResult('u', 'u__status', 'status');
$rsm->addScalarResult('sclr0', 'nameUpper');
$rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber'); $rsm->addFieldResult('p', 'p__phonenumber', 'phonenumber');
$rsm->addScalarResult('sclr0', 'nameUpper');
// Faked result set // Faked result set
$resultSet = array( $resultSet = array(
@ -202,32 +247,32 @@ class ObjectHydratorTest extends HydrationTestCase
array( array(
'u__id' => '1', 'u__id' => '1',
'u__status' => 'developer', 'u__status' => 'developer',
'sclr0' => 'ROMANB',
'p__phonenumber' => '42', 'p__phonenumber' => '42',
'sclr0' => 'ROMANB',
), ),
array( array(
'u__id' => '1', 'u__id' => '1',
'u__status' => 'developer', 'u__status' => 'developer',
'sclr0' => 'ROMANB',
'p__phonenumber' => '43', 'p__phonenumber' => '43',
'sclr0' => 'ROMANB',
), ),
array( array(
'u__id' => '2', 'u__id' => '2',
'u__status' => 'developer', 'u__status' => 'developer',
'p__phonenumber' => '91',
'sclr0' => 'JWAGE', 'sclr0' => 'JWAGE',
'p__phonenumber' => '91'
) )
); );
$stmt = new HydratorMockStatement($resultSet); $stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
$result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true));
$this->assertEquals(2, count($result)); $this->assertEquals(2, count($result));
$this->assertTrue(is_array($result));
$this->assertTrue(is_array($result[0])); $this->assertInternalType('array', $result);
$this->assertTrue(is_array($result[1])); $this->assertInternalType('array', $result[0]);
$this->assertInternalType('array', $result[1]);
$this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0][0]); $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0][0]);
$this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[0][0]->phonenumbers); $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[0][0]->phonenumbers);
@ -239,6 +284,7 @@ class ObjectHydratorTest extends HydrationTestCase
// first user => 2 phonenumbers // first user => 2 phonenumbers
$this->assertEquals(2, count($result[0][0]->phonenumbers)); $this->assertEquals(2, count($result[0][0]->phonenumbers));
$this->assertEquals('ROMANB', $result[0]['nameUpper']); $this->assertEquals('ROMANB', $result[0]['nameUpper']);
// second user => 1 phonenumber // second user => 1 phonenumber
$this->assertEquals(1, count($result[1][0]->phonenumbers)); $this->assertEquals(1, count($result[1][0]->phonenumbers));
$this->assertEquals('JWAGE', $result[1]['nameUpper']); $this->assertEquals('JWAGE', $result[1]['nameUpper']);
@ -249,8 +295,11 @@ class ObjectHydratorTest extends HydrationTestCase
} }
/** /**
* select u, count(p.phonenumber) numPhones from User u * SELECT PARTIAL u.{id, status},
* join u.phonenumbers p group by u.id * COUNT(p.phonenumber) numPhones
* FROM User u
* JOIN u.phonenumbers p
* GROUP BY u.id
*/ */
public function testMixedQueryNormalJoin() public function testMixedQueryNormalJoin()
{ {
@ -277,15 +326,17 @@ class ObjectHydratorTest extends HydrationTestCase
$stmt = new HydratorMockStatement($resultSet); $stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
$result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true));
$this->assertEquals(2, count($result)); $this->assertEquals(2, count($result));
$this->assertTrue(is_array($result));
$this->assertTrue(is_array($result[0])); $this->assertInternalType('array', $result);
$this->assertTrue(is_array($result[1])); $this->assertInternalType('array', $result[0]);
$this->assertInternalType('array', $result[1]);
// first user => 2 phonenumbers // first user => 2 phonenumbers
$this->assertEquals(2, $result[0]['numPhones']); $this->assertEquals(2, $result[0]['numPhones']);
// second user => 1 phonenumber // second user => 1 phonenumber
$this->assertEquals(1, $result[1]['numPhones']); $this->assertEquals(1, $result[1]['numPhones']);
$this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0][0]); $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[0][0]);
@ -293,8 +344,13 @@ class ObjectHydratorTest extends HydrationTestCase
} }
/** /**
* select u, p, upper(u.name) nameUpper from User u index by u.id * SELECT u,
* join u.phonenumbers p indexby p.phonenumber * p,
* UPPER(u.name) nameUpper
* FROM User u
* INDEX BY u.id
* JOIN u.phonenumbers p
* INDEX BY p.phonenumber
*/ */
public function testMixedQueryFetchJoinCustomIndex() public function testMixedQueryFetchJoinCustomIndex()
{ {
@ -339,13 +395,13 @@ class ObjectHydratorTest extends HydrationTestCase
$stmt = new HydratorMockStatement($resultSet); $stmt = new HydratorMockStatement($resultSet);
$hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em); $hydrator = new \Doctrine\ORM\Internal\Hydration\ObjectHydrator($this->_em);
$result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true)); $result = $hydrator->hydrateAll($stmt, $rsm, array(Query::HINT_FORCE_PARTIAL_LOAD => true));
$this->assertEquals(2, count($result)); $this->assertEquals(2, count($result));
$this->assertTrue(is_array($result));
$this->assertTrue(is_array($result[1])); $this->assertInternalType('array', $result);
$this->assertTrue(is_array($result[2])); $this->assertInternalType('array', $result[1]);
$this->assertInternalType('array', $result[2]);
// test the scalar values // test the scalar values
$this->assertEquals('ROMANB', $result[1]['nameUpper']); $this->assertEquals('ROMANB', $result[1]['nameUpper']);
@ -354,10 +410,13 @@ class ObjectHydratorTest extends HydrationTestCase
$this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[1][0]); $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[1][0]);
$this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[2][0]); $this->assertInstanceOf('Doctrine\Tests\Models\CMS\CmsUser', $result[2][0]);
$this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[1][0]->phonenumbers); $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $result[1][0]->phonenumbers);
// first user => 2 phonenumbers. notice the custom indexing by user id // first user => 2 phonenumbers. notice the custom indexing by user id
$this->assertEquals(2, count($result[1][0]->phonenumbers)); $this->assertEquals(2, count($result[1][0]->phonenumbers));
// second user => 1 phonenumber. notice the custom indexing by user id // second user => 1 phonenumber. notice the custom indexing by user id
$this->assertEquals(1, count($result[2][0]->phonenumbers)); $this->assertEquals(1, count($result[2][0]->phonenumbers));
// test the custom indexing of the phonenumbers // test the custom indexing of the phonenumbers
$this->assertTrue(isset($result[1][0]->phonenumbers['42'])); $this->assertTrue(isset($result[1][0]->phonenumbers['42']));
$this->assertTrue(isset($result[1][0]->phonenumbers['43'])); $this->assertTrue(isset($result[1][0]->phonenumbers['43']));