-
-
Notifications
You must be signed in to change notification settings - Fork 504
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1355 from malarzm/proxy-public-prop
Fix initializing lazy properties during hydration
- Loading branch information
Showing
2 changed files
with
102 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1346Test.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
namespace Doctrine\ODM\MongoDB\Tests\Functional\Ticket; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; | ||
|
||
class GH1346Test extends \Doctrine\ODM\MongoDB\Tests\BaseTest | ||
{ | ||
/** | ||
* @group GH1346Test | ||
*/ | ||
public function testPublicProperty() | ||
{ | ||
$referenced1 = new GH1346ReferencedDocument(); | ||
$referenced2 = new GH1346ReferencedDocument(); | ||
$gH1346Document = new GH1346Document(); | ||
$gH1346Document->addReference($referenced1); | ||
|
||
$this->dm->persist($referenced2); | ||
$this->dm->persist($referenced1); | ||
$this->dm->persist($gH1346Document); | ||
$this->dm->flush(); | ||
$this->dm->clear(); | ||
|
||
$gH1346Document = $this->dm->getRepository(__NAMESPACE__ . '\GH1346Document')->find($gH1346Document->getId()); | ||
$referenced2 = $this->dm->getRepository(__NAMESPACE__ . '\GH1346ReferencedDocument')->find($referenced2->getId()); | ||
|
||
$gH1346Document->addReference($referenced2); | ||
|
||
$this->dm->persist($gH1346Document); | ||
$this->dm->flush(); | ||
|
||
$this->assertEquals(2, $gH1346Document->getReferences()->count()); | ||
|
||
$this->dm->flush(); | ||
} | ||
} | ||
|
||
|
||
/** | ||
* @ODM\Document | ||
*/ | ||
class GH1346Document | ||
{ | ||
/** @ODM\Id */ | ||
protected $id; | ||
|
||
/** @ODM\ReferenceMany(targetDocument="GH1346ReferencedDocument") */ | ||
protected $references; | ||
|
||
public function __construct() | ||
{ | ||
$this->references = new ArrayCollection(); | ||
} | ||
|
||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
|
||
public function addReference($otherReference) | ||
{ | ||
$this->references->add($otherReference); | ||
} | ||
|
||
public function getReferences() | ||
{ | ||
return $this->references; | ||
} | ||
} | ||
|
||
/** | ||
* @ODM\Document | ||
*/ | ||
class GH1346ReferencedDocument | ||
{ | ||
/** @ODM\Field(type="string") */ | ||
public $test; | ||
|
||
/** @ODM\Id */ | ||
protected $id; | ||
|
||
public function setTest($test) | ||
{ | ||
$this->test = $test; | ||
} | ||
|
||
public function getId() | ||
{ | ||
return $this->id; | ||
} | ||
} |