[2.0] added tests for lazy loading; added error_reporting level; wired association proxy factory
This commit is contained in:
parent
b8090c99a3
commit
3747365b1c
4 changed files with 61 additions and 38 deletions
|
@ -68,18 +68,7 @@ class ProxyFactory
|
|||
*/
|
||||
public function getAssociationProxy($owner, \Doctrine\ORM\Mapping\AssociationMapping $assoc)
|
||||
{
|
||||
throw new Exception("Not yet implemented.");
|
||||
$proxyClassName = str_replace('\\', '_', $assoc->getTargetEntityName()) . 'AProxy';
|
||||
if ( ! class_exists($proxyClassName, false)) {
|
||||
$this->_em->getMetadataFactory()->setMetadataFor(self::$_ns . $proxyClassName, $this->_em->getClassMetadata($assoc->getTargetEntityName()));
|
||||
$fileName = $this->_cacheDir . $proxyClassName . '.g.php';
|
||||
if ( ! file_exists($fileName)) {
|
||||
$this->_generateAssociationProxyClass($assoc->getTargetEntityName(), $proxyClassName, $fileName);
|
||||
}
|
||||
require $fileName;
|
||||
}
|
||||
$proxyClassName = '\\' . self::$_ns . $proxyClassName;
|
||||
|
||||
$proxyClassName = $this->_generator->generateAssociationProxyClass($assoc->getTargetEntityName());
|
||||
return new $proxyClassName($this->_em, $assoc, $owner);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Doctrine\Tests\ORM\Functional;
|
|||
|
||||
use Doctrine\Tests\Models\ECommerce\ECommerceCart;
|
||||
use Doctrine\Tests\Models\ECommerce\ECommerceCustomer;
|
||||
use Doctrine\ORM\Mapping\AssociationMapping;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
|
@ -53,6 +54,33 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional
|
|||
}
|
||||
|
||||
public function testEagerLoad()
|
||||
{
|
||||
$this->_createFixture();
|
||||
|
||||
$query = $this->_em->createQuery('select c, ca from Doctrine\Tests\Models\ECommerce\ECommerceCustomer c join c.cart ca');
|
||||
$result = $query->getResultList();
|
||||
$customer = $result[0];
|
||||
|
||||
$this->assertTrue($customer->getCart() instanceof ECommerceCart);
|
||||
$this->assertEquals('paypal', $customer->getCart()->getPayment());
|
||||
}
|
||||
|
||||
public function testLazyLoad() {
|
||||
$this->markTestSkipped();
|
||||
$this->_createFixture();
|
||||
$this->_em->getConfiguration()->setAllowPartialObjects(false);
|
||||
$metadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceCustomer');
|
||||
$metadata->getAssociationMapping('cart')->fetchMode = AssociationMapping::FETCH_LAZY;
|
||||
|
||||
$query = $this->_em->createQuery('select c from Doctrine\Tests\Models\ECommerce\ECommerceCustomer c');
|
||||
$result = $query->getResultList();
|
||||
$customer = $result[0];
|
||||
|
||||
$this->assertTrue($customer->getCart() instanceof ECommerceCart);
|
||||
$this->assertEquals('paypal', $customer->getCart()->getPayment());
|
||||
}
|
||||
|
||||
protected function _createFixture()
|
||||
{
|
||||
$customer = new ECommerceCustomer;
|
||||
$customer->setName('Giorgio');
|
||||
|
@ -64,19 +92,7 @@ class OneToOneBidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctional
|
|||
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$query = $this->_em->createQuery('select c, ca from Doctrine\Tests\Models\ECommerce\ECommerceCustomer c join c.cart ca');
|
||||
$result = $query->getResultList();
|
||||
$customer = $result[0];
|
||||
|
||||
$this->assertTrue($customer->getCart() instanceof ECommerceCart);
|
||||
$this->assertEquals('paypal', $customer->getCart()->getPayment());
|
||||
}
|
||||
|
||||
/* TODO: not yet implemented
|
||||
public function testLazyLoad() {
|
||||
|
||||
}*/
|
||||
|
||||
public function assertCartForeignKeyIs($value) {
|
||||
$foreignKey = $this->_em->getConnection()->execute('SELECT customer_id FROM ecommerce_carts WHERE id=?', array($this->cart->getId()))->fetchColumn();
|
||||
|
|
|
@ -4,6 +4,7 @@ namespace Doctrine\Tests\ORM\Functional;
|
|||
|
||||
use Doctrine\Tests\Models\ECommerce\ECommerceProduct;
|
||||
use Doctrine\Tests\Models\ECommerce\ECommerceShipping;
|
||||
use Doctrine\ORM\Mapping\AssociationMapping;
|
||||
|
||||
require_once __DIR__ . '/../../TestInit.php';
|
||||
|
||||
|
@ -45,7 +46,34 @@ class OneToOneUnidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona
|
|||
$this->assertForeignKeyIs(null);
|
||||
}
|
||||
|
||||
public function testEagerLoad()
|
||||
public function _testEagerLoad()
|
||||
{
|
||||
$this->_createFixture();
|
||||
|
||||
$query = $this->_em->createQuery('select p, s from Doctrine\Tests\Models\ECommerce\ECommerceProduct p left join p.shipping s');
|
||||
$result = $query->getResultList();
|
||||
$product = $result[0];
|
||||
|
||||
$this->assertTrue($product->getShipping() instanceof ECommerceShipping);
|
||||
$this->assertEquals(1, $product->getShipping()->getDays());
|
||||
}
|
||||
|
||||
public function testLazyLoad() {
|
||||
$this->markTestSkipped();
|
||||
$this->_createFixture();
|
||||
$this->_em->getConfiguration()->setAllowPartialObjects(false);
|
||||
$metadata = $this->_em->getClassMetadata('Doctrine\Tests\Models\ECommerce\ECommerceProduct');
|
||||
$metadata->getAssociationMapping('shipping')->fetchMode = AssociationMapping::FETCH_LAZY;
|
||||
|
||||
$query = $this->_em->createQuery('select p from Doctrine\Tests\Models\ECommerce\ECommerceProduct p');
|
||||
$result = $query->getResultList();
|
||||
$product = $result[0];
|
||||
|
||||
$this->assertTrue($product->getShipping() instanceof ECommerceShipping);
|
||||
$this->assertEquals(1, $product->getShipping()->getDays());
|
||||
}
|
||||
|
||||
protected function _createFixture()
|
||||
{
|
||||
$product = new ECommerceProduct;
|
||||
$product->setName('Php manual');
|
||||
|
@ -57,19 +85,7 @@ class OneToOneUnidirectionalAssociationTest extends \Doctrine\Tests\OrmFunctiona
|
|||
|
||||
$this->_em->flush();
|
||||
$this->_em->clear();
|
||||
|
||||
$query = $this->_em->createQuery('select p, s from Doctrine\Tests\Models\ECommerce\ECommerceProduct p left join p.shipping s');
|
||||
$result = $query->getResultList();
|
||||
$product = $result[0];
|
||||
|
||||
$this->assertTrue($product->getShipping() instanceof ECommerceShipping);
|
||||
$this->assertEquals(1, $product->getShipping()->getDays());
|
||||
}
|
||||
|
||||
/* TODO: not yet implemented
|
||||
public function testLazyLoad() {
|
||||
|
||||
}*/
|
||||
|
||||
public function assertForeignKeyIs($value) {
|
||||
$foreignKey = $this->_em->getConnection()->execute('SELECT shipping_id FROM ecommerce_products WHERE id=?', array($this->product->getId()))->fetchColumn();
|
||||
|
|
|
@ -4,6 +4,8 @@
|
|||
*/
|
||||
namespace Doctrine\Tests;
|
||||
|
||||
error_reporting(E_ALL | E_STRICT);
|
||||
|
||||
require_once 'PHPUnit/Framework.php';
|
||||
require_once 'PHPUnit/TextUI/TestRunner.php';
|
||||
require_once __DIR__ . '/../../../lib/Doctrine/Common/ClassLoader.php';
|
||||
|
@ -13,4 +15,4 @@ $classLoader = new \Doctrine\Common\ClassLoader();
|
|||
set_include_path(
|
||||
get_include_path()
|
||||
. PATH_SEPARATOR . __DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'lib'
|
||||
);
|
||||
);
|
||||
|
|
Loading…
Add table
Reference in a new issue