ReferenceProxyTest.php 1.25 KB
Newer Older
1 2 3 4
<?php

namespace Doctrine\Tests\ORM\Functional;

5 6
use Doctrine\ORM\Proxy\ProxyFactory;
use Doctrine\ORM\Proxy\ProxyClassGenerator;
7 8 9 10 11 12
use Doctrine\Tests\Models\ECommerce\ECommerceProduct;

require_once __DIR__ . '/../../TestInit.php';

/**
 * Tests the generation of a proxy object for lazy loading.
13
 * @author Giorgio Sironi <piccoloprincipeazzurro@gmail.com>
14
 * @author Benjamin Eberlei <kontakt@beberlei.de>
15
 */
16
class ReferenceProxyTest extends \Doctrine\Tests\OrmFunctionalTestCase
17 18 19 20 21
{
    protected function setUp()
    {
        $this->useModelSet('ecommerce');
        parent::setUp();
22 23 24 25 26
        $this->_factory = new ProxyFactory(
                $this->_em,
                __DIR__ . '/../../Proxies',
                'Doctrine\Tests\Proxies',
                true);
27 28 29 30 31 32
    }

    public function testLazyLoadsFieldValuesFromDatabase()
    {
        $product = new ECommerceProduct();
        $product->setName('Doctrine Cookbook');
romanb's avatar
romanb committed
33
        $this->_em->persist($product);
34 35 36

        $this->_em->flush();
        $this->_em->clear();
romanb's avatar
romanb committed
37 38
        
        $id = $product->getId();
39

40
        $productProxy = $this->_factory->getProxy('Doctrine\Tests\Models\ECommerce\ECommerceProduct', array('id' => $id));
41 42 43
        $this->assertEquals('Doctrine Cookbook', $productProxy->getName());
    }
}