2009-01-14 00:56:43 +03:00
|
|
|
<?php
|
|
|
|
|
2009-01-22 22:38:10 +03:00
|
|
|
namespace Doctrine\Tests\ORM\Hydration;
|
|
|
|
|
|
|
|
use Doctrine\Tests\Mocks\HydratorMockStatement;
|
2009-04-09 22:12:48 +04:00
|
|
|
use Doctrine\ORM\Query\ResultSetMapping;
|
2009-01-22 22:38:10 +03:00
|
|
|
|
2009-01-24 19:56:44 +03:00
|
|
|
require_once __DIR__ . '/../../TestInit.php';
|
2009-01-14 00:56:43 +03:00
|
|
|
|
2009-06-15 22:25:47 +04:00
|
|
|
class ScalarHydratorTest extends HydrationTestCase
|
2009-01-14 00:56:43 +03:00
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Select u.id, u.name from CmsUser u
|
|
|
|
*/
|
|
|
|
public function testNewHydrationSimpleEntityQuery()
|
|
|
|
{
|
2009-04-09 22:12:48 +04:00
|
|
|
$rsm = new ResultSetMapping;
|
2009-05-21 23:18:14 +04:00
|
|
|
$rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u');
|
2009-04-09 22:12:48 +04:00
|
|
|
$rsm->addFieldResult('u', 'u__id', 'id');
|
|
|
|
$rsm->addFieldResult('u', 'u__name', 'name');
|
2009-01-14 00:56:43 +03:00
|
|
|
|
|
|
|
// Faked result set
|
|
|
|
$resultSet = array(
|
|
|
|
array(
|
|
|
|
'u__id' => '1',
|
|
|
|
'u__name' => 'romanb'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'u__id' => '2',
|
|
|
|
'u__name' => 'jwage'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
|
2009-01-22 22:38:10 +03:00
|
|
|
$stmt = new HydratorMockStatement($resultSet);
|
|
|
|
$hydrator = new \Doctrine\ORM\Internal\Hydration\ScalarHydrator($this->_em);
|
2009-01-14 00:56:43 +03:00
|
|
|
|
2009-04-12 23:02:12 +04:00
|
|
|
$result = $hydrator->hydrateAll($stmt, $rsm);
|
2009-01-14 00:56:43 +03:00
|
|
|
|
|
|
|
$this->assertTrue(is_array($result));
|
|
|
|
$this->assertEquals(2, count($result));
|
|
|
|
$this->assertEquals('romanb', $result[0]['u_name']);
|
|
|
|
$this->assertEquals(1, $result[0]['u_id']);
|
|
|
|
$this->assertEquals('jwage', $result[1]['u_name']);
|
|
|
|
$this->assertEquals(2, $result[1]['u_id']);
|
|
|
|
}
|
2010-03-20 20:40:30 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @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);
|
|
|
|
}
|
2010-07-29 00:09:43 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @group DDC-644
|
|
|
|
*/
|
|
|
|
public function testSkipUnknownColumns()
|
|
|
|
{
|
|
|
|
$rsm = new ResultSetMapping;
|
|
|
|
$rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u');
|
|
|
|
$rsm->addFieldResult('u', 'u__id', 'id');
|
|
|
|
$rsm->addFieldResult('u', 'u__name', 'name');
|
|
|
|
$rsm->addScalarResult('foo1', 'foo');
|
|
|
|
$rsm->addScalarResult('bar2', 'bar');
|
|
|
|
$rsm->addScalarResult('baz3', 'baz');
|
|
|
|
|
|
|
|
$resultSet = array(
|
|
|
|
array(
|
|
|
|
'u__id' => '1',
|
|
|
|
'u__name' => 'romanb',
|
|
|
|
'foo1' => 'A',
|
|
|
|
'bar2' => 'B',
|
|
|
|
'baz3' => 'C',
|
|
|
|
'foo' => 'bar', // Unknown!
|
|
|
|
),
|
|
|
|
);
|
|
|
|
|
|
|
|
$stmt = new HydratorMockStatement($resultSet);
|
|
|
|
$hydrator = new \Doctrine\ORM\Internal\Hydration\ScalarHydrator($this->_em);
|
|
|
|
|
|
|
|
$result = $hydrator->hydrateAll($stmt, $rsm);
|
|
|
|
}
|
2009-02-18 10:59:11 +03:00
|
|
|
}
|