46 lines
1.1 KiB
PHP
46 lines
1.1 KiB
PHP
|
<?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;
|
||
|
$rsm->addEntityResult($this->_em->getClassMetadata('Doctrine\Tests\Models\CMS\CmsUser'), 'u');
|
||
|
$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);
|
||
|
}
|
||
|
}
|
||
|
|