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;
|
|
|
|
|
|
|
|
require_once dirname(__FILE__) . '/../../TestInit.php';
|
2009-01-14 00:56:43 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Description of SingleScalarHydratorTest
|
|
|
|
*
|
|
|
|
* @author robo
|
|
|
|
*/
|
2009-01-22 22:38:10 +03:00
|
|
|
class SingleScalarHydratorTest extends HydrationTest
|
2009-01-14 00:56:43 +03:00
|
|
|
{
|
|
|
|
/** Result set provider for the HYDRATE_SINGLE_SCALAR tests */
|
|
|
|
public static function singleScalarResultSetProvider() {
|
|
|
|
return array(
|
|
|
|
// valid
|
|
|
|
array('name' => 'result1',
|
|
|
|
'resultSet' => array(
|
|
|
|
array(
|
|
|
|
'u__name' => 'romanb'
|
|
|
|
)
|
|
|
|
)),
|
|
|
|
// valid
|
|
|
|
array('name' => 'result2',
|
|
|
|
'resultSet' => array(
|
|
|
|
array(
|
|
|
|
'u__id' => '1'
|
|
|
|
)
|
|
|
|
)),
|
|
|
|
// invalid
|
|
|
|
array('name' => 'result3',
|
|
|
|
'resultSet' => array(
|
|
|
|
array(
|
|
|
|
'u__id' => '1',
|
|
|
|
'u__name' => 'romanb'
|
|
|
|
)
|
|
|
|
)),
|
|
|
|
// invalid
|
|
|
|
array('name' => 'result4',
|
|
|
|
'resultSet' => array(
|
|
|
|
array(
|
|
|
|
'u__id' => '1'
|
|
|
|
),
|
|
|
|
array(
|
|
|
|
'u__id' => '2'
|
|
|
|
)
|
|
|
|
)),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* select u.name from CmsUser u where u.id = 1
|
|
|
|
*
|
|
|
|
* @dataProvider singleScalarResultSetProvider
|
|
|
|
*/
|
|
|
|
public function testHydrateSingleScalar($name, $resultSet)
|
|
|
|
{
|
|
|
|
// Faked query components
|
|
|
|
$queryComponents = array(
|
|
|
|
'u' => array(
|
2009-01-22 22:38:10 +03:00
|
|
|
'metadata' => $this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'),
|
2009-01-14 00:56:43 +03:00
|
|
|
'parent' => null,
|
|
|
|
'relation' => null,
|
|
|
|
'map' => null
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
// Faked table alias map
|
|
|
|
$tableAliasMap = array(
|
|
|
|
'u' => 'u'
|
|
|
|
);
|
|
|
|
|
2009-01-22 22:38:10 +03:00
|
|
|
$stmt = new HydratorMockStatement($resultSet);
|
|
|
|
$hydrator = new \Doctrine\ORM\Internal\Hydration\SingleScalarHydrator($this->_em);
|
2009-01-14 00:56:43 +03:00
|
|
|
|
|
|
|
if ($name == 'result1') {
|
|
|
|
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult(
|
2009-01-15 16:30:44 +03:00
|
|
|
$queryComponents, $tableAliasMap));
|
2009-01-14 00:56:43 +03:00
|
|
|
$this->assertEquals('romanb', $result);
|
|
|
|
} else if ($name == 'result2') {
|
|
|
|
$result = $hydrator->hydrateAll($stmt, $this->_createParserResult(
|
2009-01-15 16:30:44 +03:00
|
|
|
$queryComponents, $tableAliasMap));
|
2009-01-14 00:56:43 +03:00
|
|
|
$this->assertEquals(1, $result);
|
|
|
|
} else if ($name == 'result3' || $name == 'result4') {
|
|
|
|
try {
|
|
|
|
$result = $hydrator->hydrateall($stmt, $this->_createParserResult(
|
2009-01-15 16:30:44 +03:00
|
|
|
$queryComponents, $tableAliasMap));
|
2009-01-14 00:56:43 +03:00
|
|
|
$this->fail();
|
2009-01-22 22:38:10 +03:00
|
|
|
} catch (\Doctrine\ORM\Exceptions\HydrationException $ex) {}
|
2009-01-14 00:56:43 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|