Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[MODM-52] Fixing issue with computing changesets of nested embedded d…
…ocuments that are multiple levels deep
- Loading branch information
Showing
3 changed files
with
122 additions
and
37 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
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
58 changes: 58 additions & 0 deletions
58
tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/MODM52Test.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,58 @@ | ||
<?php | ||
|
||
namespace Doctrine\ODM\MongoDB\Tests\Functional\Ticket; | ||
|
||
require_once __DIR__ . '/../../../../../../TestInit.php'; | ||
|
||
class MODM52Test extends \Doctrine\ODM\MongoDB\Tests\BaseTest | ||
{ | ||
public function testTest() | ||
{ | ||
$emb = new MODM52Embedded(array(new MODM52Embedded(), new MODM52Embedded())); | ||
$doc = new MODM52Doc(array($emb)); | ||
|
||
$this->dm->persist($doc); | ||
$this->dm->flush(array('safe' => true)); | ||
$this->dm->refresh($doc); | ||
|
||
// change nested embedded collection: | ||
$doc->getItem(0)->removeItem(1); | ||
$before = count($doc->getItem(0)->getItems()); | ||
|
||
$this->dm->persist($doc); | ||
$this->dm->flush(); | ||
$this->dm->refresh($doc); | ||
|
||
$after = count($doc->getItem(0)->getItems()); | ||
$this->assertEquals(1, $before); | ||
$this->assertEquals(1, $after); | ||
} | ||
} | ||
|
||
/** | ||
* @MappedSuperClass | ||
*/ | ||
class MODM52Container | ||
{ | ||
/** @String */ | ||
protected $tmp = 'ensureSaved'; | ||
|
||
/** @EmbedMany(targetDocument="MODM52Embedded", cascade="all", strategy="set") */ | ||
protected $items = array(); | ||
|
||
function __construct($items = null) {if($items) $this->items = $items;} | ||
function getItems() {return $this->items;} | ||
function getItem($index) {return $this->items[$index];} | ||
function removeItem($i) {unset($this->items[$i]);} | ||
} | ||
|
||
/** @EmbeddedDocument */ | ||
class MODM52Embedded extends MODM52Container | ||
{} | ||
|
||
/** @Document(db="tests", collection="tests") */ | ||
class MODM52Doc extends MODM52Container | ||
{ | ||
/** @Id */ | ||
protected $id; | ||
} |