Skip to content

Commit

Permalink
Proxy not initialized when parent has get<IDENTIFIER> function. Fixes…
Browse files Browse the repository at this point in the history
… DDC-1625
  • Loading branch information
Miha Vrhovnik authored and beberlei committed Feb 5, 2012
1 parent 5675e8c commit 34ccde9
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Proxy/ProxyFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ private function isShortIdentifierGetter($method, $class)
);

if ($cheapCheck) {
$code = file($class->reflClass->getFileName());
$code = file($method->getDeclaringClass()->getFileName());
$code = trim(implode(" ", array_slice($code, $method->getStartLine() - 1, $method->getEndLine() - $method->getStartLine() + 1)));

$pattern = sprintf(self::PATTERN_MATCH_ID_METHOD, $method->getName(), $identifier);
Expand Down
28 changes: 28 additions & 0 deletions tests/Doctrine/Tests/ORM/Functional/ReferenceProxyTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Doctrine\ORM\Proxy\ProxyClassGenerator;
use Doctrine\Tests\Models\ECommerce\ECommerceProduct;
use Doctrine\Tests\Models\ECommerce\ECommerceShipping;
use Doctrine\Tests\Models\Company\CompanyAuction;

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

Expand Down Expand Up @@ -39,6 +40,18 @@ public function createProduct()
return $product->getId();
}

public function createAuction()
{
$event = new CompanyAuction();
$event->setData('Doctrine Cookbook');
$this->_em->persist($event);

$this->_em->flush();
$this->_em->clear();

return $event->getId();
}

public function testLazyLoadsFieldValuesFromDatabase()
{
$id = $this->createProduct();
Expand Down Expand Up @@ -161,6 +174,21 @@ public function testDoNotInitializeProxyOnGettingTheIdentifier()
$this->assertFalse($entity->__isInitialized__, "Getting the identifier doesn't initialize the proxy.");
}

/**
* @group DDC-1625
*/
public function testDoNotInitializeProxyOnGettingTheIdentifier_DDC_1625()
{
$id = $this->createAuction();

/* @var $entity Doctrine\Tests\Models\Company\CompanyAuction */
$entity = $this->_em->getReference('Doctrine\Tests\Models\Company\CompanyAuction' , $id);

$this->assertFalse($entity->__isInitialized__, "Pre-Condition: Object is unitialized proxy.");
$this->assertEquals($id, $entity->getId());
$this->assertFalse($entity->__isInitialized__, "Getting the identifier doesn't initialize the proxy when extending.");
}

public function testDoNotInitializeProxyOnGettingTheIdentifierAndReturnTheRightType()
{
$product = new ECommerceProduct();
Expand Down

0 comments on commit 34ccde9

Please sign in to comment.