ResultSetMappingTest.php 2.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. <?php
  2. namespace Doctrine\Tests\ORM\Hydration;
  3. use Doctrine\ORM\Query\ResultSetMapping;
  4. use Doctrine\ORM\Mapping\ClassMetadata;
  5. require_once __DIR__ . '/../../TestInit.php';
  6. /**
  7. * Description of ResultSetMappingTest
  8. *
  9. * @author robo
  10. */
  11. class ResultSetMappingTest extends \Doctrine\Tests\OrmTestCase
  12. {
  13. private $_rsm;
  14. private $_em;
  15. protected function setUp() {
  16. parent::setUp();
  17. $this->_rsm = new ResultSetMapping;
  18. $this->_em = $this->_getTestEntityManager();
  19. }
  20. /**
  21. * For SQL: SELECT id, status, username, name FROM cms_users
  22. */
  23. public function testBasicResultSetMapping()
  24. {
  25. $this->_rsm->addEntityResult(
  26. 'Doctrine\Tests\Models\CMS\CmsUser',
  27. 'u'
  28. );
  29. $this->_rsm->addFieldResult('u', 'id', 'id');
  30. $this->_rsm->addFieldResult('u', 'status', 'status');
  31. $this->_rsm->addFieldResult('u', 'username', 'username');
  32. $this->_rsm->addFieldResult('u', 'name', 'name');
  33. $this->assertFalse($this->_rsm->isScalarResult('id'));
  34. $this->assertFalse($this->_rsm->isScalarResult('status'));
  35. $this->assertFalse($this->_rsm->isScalarResult('username'));
  36. $this->assertFalse($this->_rsm->isScalarResult('name'));
  37. $this->assertTrue($this->_rsm->getClassName('u') == 'Doctrine\Tests\Models\CMS\CmsUser');
  38. $class = $this->_rsm->getDeclaringClass('id');
  39. $this->assertTrue($class == 'Doctrine\Tests\Models\CMS\CmsUser');
  40. $this->assertEquals('u', $this->_rsm->getEntityAlias('id'));
  41. $this->assertEquals('u', $this->_rsm->getEntityAlias('status'));
  42. $this->assertEquals('u', $this->_rsm->getEntityAlias('username'));
  43. $this->assertEquals('u', $this->_rsm->getEntityAlias('name'));
  44. $this->assertEquals('id', $this->_rsm->getFieldName('id'));
  45. $this->assertEquals('status', $this->_rsm->getFieldName('status'));
  46. $this->assertEquals('username', $this->_rsm->getFieldName('username'));
  47. $this->assertEquals('name', $this->_rsm->getFieldName('name'));
  48. }
  49. }