[2.0] working implementation of reference proxies
This commit is contained in:
parent
9dba60a5fb
commit
0b9a2e0c0b
@ -32,6 +32,7 @@ class AllTests
|
|||||||
$suite->addTestSuite('Doctrine\Tests\ORM\EntityManagerTest');
|
$suite->addTestSuite('Doctrine\Tests\ORM\EntityManagerTest');
|
||||||
$suite->addTestSuite('Doctrine\Tests\ORM\CommitOrderCalculatorTest');
|
$suite->addTestSuite('Doctrine\Tests\ORM\CommitOrderCalculatorTest');
|
||||||
$suite->addTestSuite('Doctrine\Tests\ORM\QueryBuilderTest');
|
$suite->addTestSuite('Doctrine\Tests\ORM\QueryBuilderTest');
|
||||||
|
$suite->addTestSuite('Doctrine\Tests\ORM\DynamicProxy\GeneratorTest');
|
||||||
|
|
||||||
$suite->addTest(Query\AllTests::suite());
|
$suite->addTest(Query\AllTests::suite());
|
||||||
$suite->addTest(Hydration\AllTests::suite());
|
$suite->addTest(Hydration\AllTests::suite());
|
||||||
|
72
tests/Doctrine/Tests/ORM/DynamicProxy/GeneratorTest.php
Normal file
72
tests/Doctrine/Tests/ORM/DynamicProxy/GeneratorTest.php
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Doctrine\Tests\ORM\DynamicProxy;
|
||||||
|
|
||||||
|
use Doctrine\ORM\DynamicProxy\Generator;
|
||||||
|
use Doctrine\Tests\Mocks\ConnectionMock;
|
||||||
|
use Doctrine\Tests\Mocks\EntityManagerMock;
|
||||||
|
use Doctrine\Tests\Models\ECommerce\ECommerceCart;
|
||||||
|
use Doctrine\Tests\Models\ECommerce\ECommerceCustomer;
|
||||||
|
use Doctrine\Tests\Models\ECommerce\ECommerceFeature;
|
||||||
|
use Doctrine\Tests\Models\ECommerce\ECommerceShipping;
|
||||||
|
|
||||||
|
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.
|
||||||
|
*/
|
||||||
|
class GeneratorTest extends \Doctrine\Tests\OrmTestCase
|
||||||
|
{
|
||||||
|
private $_connectionMock;
|
||||||
|
private $_emMock;
|
||||||
|
private $_generator;
|
||||||
|
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
parent::setUp();
|
||||||
|
// SUT
|
||||||
|
$this->_connectionMock = new ConnectionMock(array(), new \Doctrine\Tests\Mocks\DriverMock());
|
||||||
|
$this->_emMock = EntityManagerMock::create($this->_connectionMock);
|
||||||
|
$this->_generator = new Generator($this->_emMock, __DIR__ . '/generated');
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function tearDown()
|
||||||
|
{
|
||||||
|
foreach (new \DirectoryIterator(__DIR__ . '/generated') as $file) {
|
||||||
|
if (strstr($file->getFilename(), '.php')) {
|
||||||
|
unlink($file->getPathname());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCreatesASubclassOfTheOriginalOne()
|
||||||
|
{
|
||||||
|
$proxyClass = $this->_generator->generateReferenceProxyClass('Doctrine\Tests\Models\ECommerce\ECommerceFeature');
|
||||||
|
$this->assertTrue(is_subclass_of($proxyClass, '\Doctrine\Tests\Models\ECommerce\ECommerceFeature'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testCanGuessADefaultTempFolder()
|
||||||
|
{
|
||||||
|
$generator = new Generator($this->_emMock);
|
||||||
|
$proxyClass = $generator->generateReferenceProxyClass('Doctrine\Tests\Models\ECommerce\ECommerceShipping');
|
||||||
|
$this->assertTrue(is_subclass_of($proxyClass, '\Doctrine\Tests\Models\ECommerce\ECommerceShipping'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testAllowsClassesWithAConstructor()
|
||||||
|
{
|
||||||
|
$proxyClass = $this->_generator->generateReferenceProxyClass('Doctrine\Tests\Models\ECommerce\ECommerceCart');
|
||||||
|
$this->assertTrue(is_subclass_of($proxyClass, '\Doctrine\Tests\Models\ECommerce\ECommerceCart'));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function _testGenerateProxiesWhichForwardsToTheModelWithTheGivenIdentifier()
|
||||||
|
{
|
||||||
|
$feature = new ECommerceFeature;
|
||||||
|
$feature->setDescription('An interesting feature');
|
||||||
|
$this->_emMock->save($feature);
|
||||||
|
$id = $feature->getId();
|
||||||
|
$this->_emMock->clear();
|
||||||
|
|
||||||
|
$proxy = $this->_generator->generateReferenceProxyClass('Doctrine\Tests\Models\ECommerce\ECommerceFeature', 1);
|
||||||
|
$this->assertEquals('An interesting feature', $proxy->getDescription());
|
||||||
|
}
|
||||||
|
}
|
@ -34,6 +34,7 @@ class AllTests
|
|||||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\OneToOneSelfReferentialAssociationTest');
|
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\OneToOneSelfReferentialAssociationTest');
|
||||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\OneToManySelfReferentialAssociationTest');
|
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\OneToManySelfReferentialAssociationTest');
|
||||||
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\ManyToManySelfReferentialAssociationTest');
|
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\ManyToManySelfReferentialAssociationTest');
|
||||||
|
$suite->addTestSuite('Doctrine\Tests\ORM\Functional\DynamicProxyTest');
|
||||||
|
|
||||||
return $suite;
|
return $suite;
|
||||||
}
|
}
|
||||||
|
38
tests/Doctrine/Tests/ORM/Functional/DynamicProxyTest.php
Normal file
38
tests/Doctrine/Tests/ORM/Functional/DynamicProxyTest.php
Normal file
@ -0,0 +1,38 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Doctrine\Tests\ORM\Functional;
|
||||||
|
|
||||||
|
use Doctrine\ORM\DynamicProxy\Factory;
|
||||||
|
use Doctrine\ORM\DynamicProxy\Generator;
|
||||||
|
use Doctrine\Tests\Models\ECommerce\ECommerceProduct;
|
||||||
|
|
||||||
|
require_once __DIR__ . '/../../TestInit.php';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests the generation of a proxy object for lazy loading.
|
||||||
|
*/
|
||||||
|
class DynamicProxyTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
||||||
|
{
|
||||||
|
private $product;
|
||||||
|
|
||||||
|
protected function setUp()
|
||||||
|
{
|
||||||
|
$this->useModelSet('ecommerce');
|
||||||
|
parent::setUp();
|
||||||
|
$this->_factory = new Factory($this->_em, new Generator($this->_em));
|
||||||
|
}
|
||||||
|
|
||||||
|
public function testLazyLoadsFieldValuesFromDatabase()
|
||||||
|
{
|
||||||
|
$product = new ECommerceProduct();
|
||||||
|
$product->setName('Doctrine Cookbook');
|
||||||
|
$this->_em->save($product);
|
||||||
|
$id = $product->getId();
|
||||||
|
|
||||||
|
$this->_em->flush();
|
||||||
|
$this->_em->clear();
|
||||||
|
|
||||||
|
$productProxy = $this->_factory->getReferenceProxy('Doctrine\Tests\Models\ECommerce\ECommerceProduct', array('id' => $id));
|
||||||
|
$this->assertEquals('Doctrine Cookbook', $productProxy->getName());
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user