2009-07-16 17:20:31 +04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Functional;
|
|
|
|
|
2009-07-16 17:59:26 +04:00
|
|
|
use Doctrine\ORM\Proxy\ProxyFactory;
|
|
|
|
use Doctrine\ORM\Proxy\ProxyClassGenerator;
|
2009-07-16 17:20:31 +04:00
|
|
|
use Doctrine\Tests\Models\ECommerce\ECommerceProduct;
|
|
|
|
|
|
|
|
require_once __DIR__ . '/../../TestInit.php';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Tests the generation of a proxy object for lazy loading.
|
2009-07-16 17:59:26 +04:00
|
|
|
* @author Giorgio Sironi <piccoloprincipeazzurro@gmail.com>
|
2009-07-16 17:20:31 +04:00
|
|
|
*/
|
2009-07-16 17:59:26 +04:00
|
|
|
class ReferenceProxyTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
2009-07-16 17:20:31 +04:00
|
|
|
{
|
|
|
|
private $product;
|
|
|
|
|
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
$this->useModelSet('ecommerce');
|
|
|
|
parent::setUp();
|
2009-10-15 00:18:36 +04:00
|
|
|
$this->_factory = new ProxyFactory(
|
|
|
|
$this->_em,
|
|
|
|
__DIR__ . '/../../Proxies',
|
|
|
|
'Doctrine\Tests\Proxies',
|
|
|
|
true);
|
2009-07-16 17:20:31 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
public function testLazyLoadsFieldValuesFromDatabase()
|
|
|
|
{
|
|
|
|
$product = new ECommerceProduct();
|
|
|
|
$product->setName('Doctrine Cookbook');
|
2009-07-19 20:54:53 +04:00
|
|
|
$this->_em->persist($product);
|
2009-07-16 17:20:31 +04:00
|
|
|
|
|
|
|
$this->_em->flush();
|
|
|
|
$this->_em->clear();
|
2009-07-19 20:54:53 +04:00
|
|
|
|
|
|
|
$id = $product->getId();
|
2009-07-16 17:20:31 +04:00
|
|
|
|
2009-10-28 18:32:55 +03:00
|
|
|
$productProxy = $this->_factory->getProxy('Doctrine\Tests\Models\ECommerce\ECommerceProduct', array('id' => $id));
|
2009-07-16 17:20:31 +04:00
|
|
|
$this->assertEquals('Doctrine Cookbook', $productProxy->getName());
|
|
|
|
}
|
|
|
|
}
|