90 lines
2.6 KiB
PHP
90 lines
2.6 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace Doctrine\Tests\ORM\Proxy;
|
||
|
|
||
|
use Doctrine\ORM\Proxy\ProxyFactory;
|
||
|
use Doctrine\Common\Proxy\ProxyGenerator;
|
||
|
use Doctrine\Tests\Mocks\ConnectionMock;
|
||
|
use Doctrine\Tests\Mocks\EntityManagerMock;
|
||
|
use Doctrine\Tests\Mocks\UnitOfWorkMock;
|
||
|
use Doctrine\Tests\Mocks\DriverMock;
|
||
|
|
||
|
require_once __DIR__ . '/../../TestInit.php';
|
||
|
|
||
|
/**
|
||
|
* Test the proxy generator. Its work is generating on-the-fly subclasses of a given model, which implement the Proxy pattern.
|
||
|
* @author Giorgio Sironi <piccoloprincipeazzurro@gmail.com>
|
||
|
*/
|
||
|
class ProxtFactoryTest extends \Doctrine\Tests\OrmTestCase
|
||
|
{
|
||
|
/**
|
||
|
* @var ConnectionMock
|
||
|
*/
|
||
|
private $connectionMock;
|
||
|
|
||
|
/**
|
||
|
* @var UnitOfWorkMock
|
||
|
*/
|
||
|
private $uowMock;
|
||
|
|
||
|
/**
|
||
|
* @var EntityManagerMock
|
||
|
*/
|
||
|
private $emMock;
|
||
|
|
||
|
/**
|
||
|
* @var \Doctrine\ORM\Proxy\ProxyFactory
|
||
|
*/
|
||
|
private $proxyFactory;
|
||
|
|
||
|
/**
|
||
|
* {@inheritDoc}
|
||
|
*/
|
||
|
protected function setUp()
|
||
|
{
|
||
|
parent::setUp();
|
||
|
$this->connectionMock = new ConnectionMock(array(), new DriverMock());
|
||
|
$this->emMock = EntityManagerMock::create($this->connectionMock);
|
||
|
$this->uowMock = new UnitOfWorkMock($this->emMock);
|
||
|
$this->emMock->setUnitOfWork($this->uowMock);
|
||
|
$this->proxyFactory = new ProxyFactory($this->emMock, sys_get_temp_dir(), 'Proxies', true);
|
||
|
}
|
||
|
|
||
|
public function testReferenceProxyDelegatesLoadingToThePersister()
|
||
|
{
|
||
|
$identifier = array('id' => 42);
|
||
|
$proxyClass = 'Proxies\__CG__\Doctrine\Tests\Models\ECommerce\ECommerceFeature';
|
||
|
$persister = $this->getMock('Doctrine\ORM\Persisters\BasicEntityPersister', array('load'), array(), '', false);
|
||
|
$this->uowMock->setEntityPersister('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $persister);
|
||
|
|
||
|
$proxy = $this->proxyFactory->getProxy('Doctrine\Tests\Models\ECommerce\ECommerceFeature', $identifier);
|
||
|
|
||
|
$persister
|
||
|
->expects($this->atLeastOnce())
|
||
|
->method('load')
|
||
|
->with($this->equalTo($identifier), $this->isInstanceOf($proxyClass))
|
||
|
->will($this->returnValue(new \stdClass()));
|
||
|
|
||
|
$proxy->getDescription();
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* @group DDC-1771
|
||
|
*/
|
||
|
public function testSkipAbstractClassesOnGeneration()
|
||
|
{
|
||
|
$cm = new \Doctrine\ORM\Mapping\ClassMetadata(__NAMESPACE__ . '\\AbstractClass');
|
||
|
$cm->initializeReflection(new \Doctrine\Common\Persistence\Mapping\RuntimeReflectionService);
|
||
|
$this->assertNotNull($cm->reflClass);
|
||
|
|
||
|
$num = $this->proxyFactory->generateProxyClasses(array($cm));
|
||
|
|
||
|
$this->assertEquals(0, $num, "No proxies generated.");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
abstract class AbstractClass
|
||
|
{
|
||
|
|
||
|
}
|