2009-04-12 23:02:12 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Functional;
|
|
|
|
|
|
|
|
use Doctrine\ORM\Query\ResultSetMapping;
|
|
|
|
use Doctrine\Tests\Models\CMS\CmsUser;
|
|
|
|
|
|
|
|
require_once __DIR__ . '/../../TestInit.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* NativeQueryTest
|
|
|
|
*
|
|
|
|
* @author robo
|
|
|
|
*/
|
|
|
|
class NativeQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|
|
|
{
|
|
|
|
protected function setUp() {
|
|
|
|
$this->useModelSet('cms');
|
|
|
|
parent::setUp();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function testBasicNativeQuery()
|
|
|
|
{
|
|
|
|
$user = new CmsUser;
|
|
|
|
$user->name = 'Roman';
|
|
|
|
$user->username = 'romanb';
|
|
|
|
$user->status = 'dev';
|
|
|
|
$this->_em->save($user);
|
|
|
|
$this->_em->flush();
|
|
|
|
|
|
|
|
$rsm = new ResultSetMapping;
|
2009-05-21 23:18:14 +04:00
|
|
|
$rsm->addEntityResult('Doctrine\Tests\Models\CMS\CmsUser', 'u');
|
2009-04-12 23:02:12 +04:00
|
|
|
$rsm->addFieldResult('u', 'id', 'id');
|
|
|
|
$rsm->addFieldResult('u', 'name', 'name');
|
|
|
|
|
|
|
|
$query = $this->_em->createNativeQuery('SELECT id, name FROM cms_users WHERE username = ?', $rsm);
|
|
|
|
$query->setParameter(1, 'romanb');
|
|
|
|
|
|
|
|
$users = $query->getResultList();
|
|
|
|
|
|
|
|
$this->assertEquals(1, count($users));
|
|
|
|
$this->assertEquals('Roman', $users[0]->name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|