Esempio n. 1
1
 /**
  * @group PR-39
  */
 public function testUnknownParentAliasThrowsException()
 {
     $rsm = new ResultSetMappingBuilder($this->_em);
     $rsm->addRootEntityFromClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsUser', 'u');
     $rsm->addJoinedEntityFromClassMetadata('Doctrine\\Tests\\Models\\CMS\\CmsAddress', 'a', 'un', 'address', array('id' => 'a_id'));
     $query = $this->_em->createNativeQuery('SELECT u.*, a.*, a.id AS a_id FROM cms_users u INNER JOIN cms_addresses a ON u.id = a.user_id WHERE u.username = ?', $rsm);
     $query->setParameter(1, 'romanb');
     $this->setExpectedException("Doctrine\\ORM\\Internal\\Hydration\\HydrationException", "The parent object of entity result with alias 'a' was not found. The parent alias is 'un'.");
     $users = $query->getResult();
 }
Esempio n. 2
0
 public function testIssue()
 {
     $config = $this->_em->getConfiguration();
     $config->addEntityNamespace('MyNamespace', 'Doctrine\\Tests\\ORM\\Functional\\Ticket');
     $user = new DDC2256User();
     $user->name = 'user';
     $group = new DDC2256Group();
     $group->name = 'group';
     $user->group = $group;
     $this->_em->persist($user);
     $this->_em->persist($group);
     $this->_em->flush();
     $this->_em->clear();
     $sql = 'SELECT u.id, u.name, g.id as group_id, g.name as group_name FROM ddc2256_users u LEFT JOIN ddc2256_groups g ON u.group_id = g.id';
     // Test ResultSetMapping.
     $rsm = new ResultSetMapping();
     $rsm->addEntityResult('MyNamespace:DDC2256User', 'u');
     $rsm->addFieldResult('u', 'id', 'id');
     $rsm->addFieldResult('u', 'name', 'name');
     $rsm->addJoinedEntityResult('MyNamespace:DDC2256Group', 'g', 'u', 'group');
     $rsm->addFieldResult('g', 'group_id', 'id');
     $rsm->addFieldResult('g', 'group_name', 'name');
     $this->_em->createNativeQuery($sql, $rsm)->getResult();
     // Test ResultSetMappingBuilder.
     $rsm = new ResultSetMappingBuilder($this->_em);
     $rsm->addRootEntityFromClassMetadata('MyNamespace:DDC2256User', 'u');
     $rsm->addJoinedEntityFromClassMetadata('MyNamespace:DDC2256Group', 'g', 'u', 'group', array('id' => 'group_id', 'name' => 'group_name'));
     $this->_em->createNativeQuery($sql, $rsm)->getResult();
 }
 /**
  * @expectedException Doctrine\ORM\Cache\CacheException
  * @expectedExceptionMessage Entity association field "Doctrine\Tests\Models\Cache\City#travels" not configured as part of the second-level cache.
  */
 public function testQueryNotCacheableAssociationException()
 {
     $uow = $this->em->getUnitOfWork();
     $key = new QueryCacheKey('query.key1', 0);
     $rsm = new ResultSetMappingBuilder($this->em);
     $cityClass = $this->em->getClassMetadata(City::CLASSNAME);
     $city = new City("City 1", null);
     $result = array($city);
     $cityClass->setFieldValue($city, 'id', 1);
     $rsm->addRootEntityFromClassMetadata(City::CLASSNAME, 'c');
     $rsm->addJoinedEntityFromClassMetadata(Travel::CLASSNAME, 't', 'c', 'travels', array('id' => 't_id'));
     $uow->registerManaged($city, array('id' => $city->getId()), array('name' => $city->getName(), 'state' => null));
     $this->queryCache->put($key, $rsm, $result);
 }