1
0
mirror of synced 2025-01-18 22:41:43 +03:00

[2.0] Renamed some methods for a better API.

This commit is contained in:
romanb 2009-08-03 17:18:37 +00:00
parent 00599a80d4
commit 0a497062c9
17 changed files with 46 additions and 48 deletions

View File

@ -303,14 +303,13 @@ abstract class AbstractQuery
/**
* Gets the list of results for the query.
*
* Alias for execute(array(), HYDRATE_OBJECT).
* Alias for execute(array(), $hydrationMode = HYDRATE_OBJECT).
*
* @return array
* @todo getResult()
*/
public function getResultList()
public function getResult($hydrationMode = self::HYDRATE_OBJECT)
{
return $this->execute(array(), self::HYDRATE_OBJECT);
return $this->execute(array(), $hydrationMode);
}
/**
@ -319,9 +318,8 @@ abstract class AbstractQuery
* Alias for execute(array(), HYDRATE_ARRAY).
*
* @return array
* @todo getArrayResult()
*/
public function getResultArray()
public function getArrayResult()
{
return $this->execute(array(), self::HYDRATE_ARRAY);
}

View File

@ -223,7 +223,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
$query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u");
$users = $query->getResultList();
$users = $query->getResult();
$this->assertEquals(1, count($users));
$this->assertEquals('Guilherme', $users[0]->name);
@ -232,7 +232,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
//$this->assertNull($users[0]->phonenumbers);
//$this->assertNull($users[0]->articles);
$usersArray = $query->getResultArray();
$usersArray = $query->getArrayResult();
$this->assertTrue(is_array($usersArray));
$this->assertEquals(1, count($usersArray));
@ -260,7 +260,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
$query = $this->_em->createQuery("select u from Doctrine\Tests\Models\CMS\CmsUser u join u.phonenumbers p");
$users = $query->getResultList();
$users = $query->getResult();
$this->assertEquals(0, count($users));
}
@ -276,7 +276,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
$query = $this->_em->createQuery("select u,p from Doctrine\Tests\Models\CMS\CmsUser u left join u.phonenumbers p");
$users = $query->getResultList();
$users = $query->getResult();
$this->assertEquals(1, count($users));
$this->assertEquals('Guilherme', $users[0]->name);
@ -308,7 +308,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
$query = $this->_em->createQuery("select u, g from Doctrine\Tests\Models\CMS\CmsUser u join u.groups g");
$result = $query->getResultList();
$result = $query->getResult();
$this->assertEquals(2, $this->_em->getUnitOfWork()->size());
$this->assertTrue($result[0] instanceof CmsUser);
@ -330,7 +330,7 @@ class BasicFunctionalTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_em->clear();
$query = $this->_em->createQuery("select u, g from Doctrine\Tests\Models\CMS\CmsUser u inner join u.groups g");
$this->assertEquals(0, count($query->getResultList()));
$this->assertEquals(0, count($query->getResult()));
}
public function testBasicRefresh()

View File

@ -41,7 +41,7 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$query = $this->_em->createQuery("select p from Doctrine\Tests\Models\Company\CompanyPerson p order by p.id asc");
$entities = $query->getResultList();
$entities = $query->getResult();
$this->assertEquals(2, count($entities));
$this->assertTrue($entities[0] instanceof CompanyPerson);
@ -56,7 +56,7 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$query = $this->_em->createQuery("select p from Doctrine\Tests\Models\Company\CompanyEmployee p");
$entities = $query->getResultList();
$entities = $query->getResult();
$this->assertEquals(1, count($entities));
$this->assertTrue($entities[0] instanceof CompanyEmployee);
@ -132,7 +132,7 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$query = $this->_em->createQuery('select p, s from Doctrine\Tests\Models\Company\CompanyPerson p join p.spouse s where p.name=\'Mary Smith\'');
$result = $query->getResultList();
$result = $query->getResult();
$this->assertEquals(1, count($result));
$this->assertTrue($result[0] instanceof CompanyPerson);
$this->assertEquals('Mary Smith', $result[0]->getName());
@ -165,7 +165,7 @@ class ClassTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$query = $this->_em->createQuery('select p, f from Doctrine\Tests\Models\Company\CompanyPerson p join p.friends f where p.name=?1');
$query->setParameter(1, 'Roman');
$result = $query->getResultList();
$result = $query->getResult();
$this->assertEquals(1, count($result));
$this->assertEquals(1, count($result[0]->getFriends()));
$this->assertEquals('Roman', $result[0]->getName());

View File

@ -30,7 +30,7 @@ class LifecycleCallbackTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_em->clear();
$query = $this->_em->createQuery("select e from Doctrine\Tests\ORM\Functional\LifecycleCallbackTestEntity e");
$result = $query->getResultList();
$result = $query->getResult();
$this->assertTrue($result[0]->postLoadCallbackInvoked);
$result[0]->value = 'hello again';

View File

@ -89,7 +89,7 @@ class ManyToManyBidirectionalAssociationTest extends AbstractManyToManyAssociati
$metadata->getAssociationMapping('products')->fetchMode = AssociationMapping::FETCH_LAZY;
$query = $this->_em->createQuery('SELECT c FROM Doctrine\Tests\Models\ECommerce\ECommerceCategory c order by c.id');
$categories = $query->getResultList();
$categories = $query->getResult();
$this->assertLoadingOfInverseSide($categories);
}
@ -102,7 +102,7 @@ class ManyToManyBidirectionalAssociationTest extends AbstractManyToManyAssociati
$metadata->getAssociationMapping('categories')->fetchMode = AssociationMapping::FETCH_LAZY;
$query = $this->_em->createQuery('SELECT p FROM Doctrine\Tests\Models\ECommerce\ECommerceProduct p order by p.id');
$products = $query->getResultList();
$products = $query->getResult();
$this->assertEquals(2, count($products));
$this->assertEquals(0, count($products[0]->getCategories()->unwrap()));
@ -128,7 +128,7 @@ class ManyToManyBidirectionalAssociationTest extends AbstractManyToManyAssociati
protected function _findProducts()
{
$query = $this->_em->createQuery('SELECT p, c FROM Doctrine\Tests\Models\ECommerce\ECommerceProduct p LEFT JOIN p.categories c ORDER BY p.id, c.id');
return $query->getResultList();
return $query->getResult();
}
public function assertLoadingOfOwningSide($products)

View File

@ -78,7 +78,7 @@ class ManyToManySelfReferentialAssociationTest extends AbstractManyToManyAssocia
$metadata->getAssociationMapping('related')->fetchMode = AssociationMapping::FETCH_LAZY;
$query = $this->_em->createQuery('SELECT p FROM Doctrine\Tests\Models\ECommerce\ECommerceProduct p');
$products = $query->getResultList();
$products = $query->getResult();
$this->assertLoadingOfOwningSide($products);
}
@ -119,6 +119,6 @@ class ManyToManySelfReferentialAssociationTest extends AbstractManyToManyAssocia
protected function _findProducts()
{
$query = $this->_em->createQuery('SELECT p, r FROM Doctrine\Tests\Models\ECommerce\ECommerceProduct p LEFT JOIN p.related r ORDER BY p.id, r.id');
return $query->getResultList();
return $query->getResult();
}
}

View File

@ -63,7 +63,7 @@ class ManyToManyUnidirectionalAssociationTest extends AbstractManyToManyAssociat
$this->_createFixture();
$query = $this->_em->createQuery('SELECT c, p FROM Doctrine\Tests\Models\ECommerce\ECommerceCart c LEFT JOIN c.products p ORDER BY c.id, p.id');
$result = $query->getResultList();
$result = $query->getResult();
$firstCart = $result[0];
$products = $firstCart->getProducts();
$secondCart = $result[1];
@ -83,7 +83,7 @@ class ManyToManyUnidirectionalAssociationTest extends AbstractManyToManyAssociat
$metadata->getAssociationMapping('products')->fetchMode = AssociationMapping::FETCH_LAZY;
$query = $this->_em->createQuery('SELECT c FROM Doctrine\Tests\Models\ECommerce\ECommerceCart c');
$result = $query->getResultList();
$result = $query->getResult();
$firstCart = $result[0];
$products = $firstCart->getProducts();
$secondCart = $result[1];

View File

@ -36,7 +36,7 @@ class NativeQueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
$query = $this->_em->createNativeQuery('SELECT id, name FROM cms_users WHERE username = ?', $rsm);
$query->setParameter(1, 'romanb');
$users = $query->getResultList();
$users = $query->getResult();
$this->assertEquals(1, count($users));
$this->assertTrue($users[0] instanceof CmsUser);

View File

@ -72,7 +72,7 @@ class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona
{
$this->_createFixture();
$query = $this->_em->createQuery('select p, f from Doctrine\Tests\Models\ECommerce\ECommerceProduct p join p.features f');
$result = $query->getResultList();
$result = $query->getResult();
$product = $result[0];
$features = $product->getFeatures();
@ -92,7 +92,7 @@ class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona
$metadata->getAssociationMapping('features')->fetchMode = AssociationMapping::FETCH_LAZY;
$query = $this->_em->createQuery('select p from Doctrine\Tests\Models\ECommerce\ECommerceProduct p');
$result = $query->getResultList();
$result = $query->getResult();
$product = $result[0];
$features = $product->getFeatures();
@ -112,7 +112,7 @@ class OneToManyBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona
$metadata->getAssociationMapping('product')->fetchMode = AssociationMapping::FETCH_LAZY;
$query = $this->_em->createQuery('select f from Doctrine\Tests\Models\ECommerce\ECommerceFeature f');
$features = $query->getResultList();
$features = $query->getResult();
$product = $features[0]->getProduct();
$this->assertTrue($product instanceof ECommerceProduct);

View File

@ -73,7 +73,7 @@ class OneToManySelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunctio
$this->_createFixture();
$query = $this->_em->createQuery('select c1, c2 from Doctrine\Tests\Models\ECommerce\ECommerceCategory c1 join c1.children c2');
$result = $query->getResultList();
$result = $query->getResult();
$this->assertEquals(1, count($result));
$parent = $result[0];
$children = $parent->getChildren();
@ -94,7 +94,7 @@ class OneToManySelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunctio
$metadata->getAssociationMapping('children')->fetchMode = AssociationMapping::FETCH_LAZY;
$query = $this->_em->createQuery('select c from Doctrine\Tests\Models\ECommerce\ECommerceCategory c order by c.id asc');
$result = $query->getResultList();
$result = $query->getResult();
$parent = $result[0];
$children = $parent->getChildren();

View File

@ -58,7 +58,7 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional
$this->_createFixture();
$query = $this->_em->createQuery('select c, ca from Doctrine\Tests\Models\ECommerce\ECommerceCustomer c join c.cart ca');
$result = $query->getResultList();
$result = $query->getResult();
$customer = $result[0];
$this->assertTrue($customer->getCart() instanceof ECommerceCart);
@ -72,7 +72,7 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional
$metadata->getAssociationMapping('customer')->fetchMode = AssociationMapping::FETCH_LAZY;
$query = $this->_em->createQuery('select c from Doctrine\Tests\Models\ECommerce\ECommerceCart c');
$result = $query->getResultList();
$result = $query->getResult();
$cart = $result[0];
$this->assertTrue($cart->getCustomer() instanceof ECommerceCustomer);
@ -86,7 +86,7 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional
$metadata->getAssociationMapping('mentor')->fetchMode = AssociationMapping::FETCH_EAGER;
$query = $this->_em->createQuery('select c from Doctrine\Tests\Models\ECommerce\ECommerceCustomer c');
$result = $query->getResultList();
$result = $query->getResult();
$customer = $result[0];
$this->assertNull($customer->getMentor());

View File

@ -53,7 +53,7 @@ class OneToOneSelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunction
$this->_createFixture();
$query = $this->_em->createQuery('select c, m from Doctrine\Tests\Models\ECommerce\ECommerceCustomer c left join c.mentor m order by c.id asc');
$result = $query->getResultList();
$result = $query->getResult();
$customer = $result[0];
$this->assertLoadingOfAssociation($customer);
}
@ -67,7 +67,7 @@ class OneToOneSelfReferentialAssociationTest extends \Doctrine\Tests\OrmFunction
$metadata->getAssociationMapping('mentor')->fetchMode = AssociationMapping::FETCH_LAZY;
$query = $this->_em->createQuery('select c from Doctrine\Tests\Models\ECommerce\ECommerceCustomer c');
$result = $query->getResultList();
$result = $query->getResult();
$customer = $result[0];
$this->assertLoadingOfAssociation($customer);
}

View File

@ -51,7 +51,7 @@ class OneToOneUnidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona
$this->_createFixture();
$query = $this->_em->createQuery('select p, s from Doctrine\Tests\Models\ECommerce\ECommerceProduct p left join p.shipping s');
$result = $query->getResultList();
$result = $query->getResult();
$product = $result[0];
$this->assertTrue($product->getShipping() instanceof ECommerceShipping);
@ -65,7 +65,7 @@ class OneToOneUnidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona
$metadata->getAssociationMapping('shipping')->fetchMode = AssociationMapping::FETCH_LAZY;
$query = $this->_em->createQuery('select p from Doctrine\Tests\Models\ECommerce\ECommerceProduct p');
$result = $query->getResultList();
$result = $query->getResult();
$product = $result[0];
$this->assertTrue($product->getShipping() instanceof ECommerceShipping);
@ -77,7 +77,7 @@ class OneToOneUnidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona
$this->_em->getConfiguration()->setAllowPartialObjects(true);
$query = $this->_em->createQuery('select p from Doctrine\Tests\Models\ECommerce\ECommerceProduct p');
$result = $query->getResultList();
$result = $query->getResult();
$product = $result[0];
$this->assertNull($product->getShipping());

View File

@ -36,7 +36,7 @@ class QueryCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase
$query->setQueryCacheDriver($cache);
$this->assertEquals(0, $cache->count());
$users = $query->getResultList();
$users = $query->getResult();
$this->assertEquals(1, $cache->count());
$this->assertTrue($cache->contains(md5('select ux from Doctrine\Tests\Models\CMS\CmsUser uxDOCTRINE_QUERY_CACHE_SALT')));
@ -48,7 +48,7 @@ class QueryCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase
$query2 = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux');
$query2->setQueryCacheDriver($cache);
$users = $query2->getResultList();
$users = $query2->getResult();
$this->assertEquals(1, $cache->count());
$this->assertTrue($cache->contains(md5('select ux from Doctrine\Tests\Models\CMS\CmsUser uxDOCTRINE_QUERY_CACHE_SALT')));

View File

@ -32,7 +32,7 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
$query = $this->_em->createQuery("select u, upper(u.name) from Doctrine\Tests\Models\CMS\CmsUser u where u.username = 'gblanco'");
$result = $query->getResultList();
$result = $query->getResult();
$this->assertEquals(1, count($result));
$this->assertTrue($result[0][0] instanceof CmsUser);
@ -41,7 +41,7 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->assertEquals('developer', $result[0][0]->status);
$this->assertEquals('GUILHERME', $result[0][1]);
$resultArray = $query->getResultArray();
$resultArray = $query->getArrayResult();
$this->assertEquals(1, count($resultArray));
$this->assertTrue(is_array($resultArray[0][0]));
$this->assertEquals('Guilherme', $resultArray[0][0]['name']);
@ -85,7 +85,7 @@ class QueryTest extends \Doctrine\Tests\OrmFunctionalTestCase
$this->_em->clear();
$query = $this->_em->createQuery("select u, a from Doctrine\Tests\Models\CMS\CmsUser u join u.articles a");
$users = $query->getResultList();
$users = $query->getResult();
$this->assertEquals(1, count($users));
$this->assertTrue($users[0] instanceof CmsUser);
$this->assertEquals(2, count($users[0]->articles));

View File

@ -36,7 +36,7 @@ class ResultCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase
$initialQueryCount = $this->_em->getConnection()->getQueryCount();
$users = $query->getResultList();
$users = $query->getResult();
$this->assertEquals($initialQueryCount + 1, $this->_em->getConnection()->getQueryCount());
$this->assertEquals(1, $cache->count());
@ -48,7 +48,7 @@ class ResultCacheTest extends \Doctrine\Tests\OrmFunctionalTestCase
$query2 = $this->_em->createQuery('select ux from Doctrine\Tests\Models\CMS\CmsUser ux');
$query2->setResultCache($cache);
$users = $query2->getResultList();
$users = $query2->getResult();
$this->assertEquals($initialQueryCount + 1, $this->_em->getConnection()->getQueryCount());
$this->assertEquals(1, $cache->count());

View File

@ -48,7 +48,7 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$query = $this->_em->createQuery("select e from Doctrine\Tests\ORM\Functional\ParentEntity e order by e.data asc");
$entities = $query->getResultList();
$entities = $query->getResult();
$this->assertEquals(2, count($entities));
$this->assertTrue(is_numeric($entities[0]->getId()));
@ -63,7 +63,7 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$query = $this->_em->createQuery("select e from Doctrine\Tests\ORM\Functional\ChildEntity e");
$entities = $query->getResultList();
$entities = $query->getResult();
$this->assertEquals(1, count($entities));
$this->assertTrue($entities[0] instanceof ChildEntity);
$this->assertTrue(is_numeric($entities[0]->getId()));
@ -74,7 +74,7 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase
$query = $this->_em->createQuery("select r,o from Doctrine\Tests\ORM\Functional\RelatedEntity r join r.owner o");
$entities = $query->getResultList();
$entities = $query->getResult();
$this->assertEquals(1, count($entities));
$this->assertTrue($entities[0] instanceof RelatedEntity);
$this->assertTrue(is_numeric($entities[0]->getId()));