Skip to content

Commit

Permalink
Add regression test for #1141 with identified embedded docs
Browse files Browse the repository at this point in the history
This addresses an earlier hypothesis that embedded documents are never scheduled for upsert (due to logic in UnitOfWork::persistNew()).
  • Loading branch information
jmikola authored and malarzm committed Jun 13, 2015
1 parent 528bea1 commit 74db05f
Showing 1 changed file with 46 additions and 6 deletions.
52 changes: 46 additions & 6 deletions tests/Doctrine/ODM/MongoDB/Tests/Functional/Ticket/GH1141Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,33 @@ public function testReplacementOfEmbedManyElements()
$book = $this->dm->getRepository(GH1141Book::CLASSNAME)->findOneBy(array('_id' => $book->id));

// Verify we see chapters A and B.
$discoveredChapterTitles = array();
foreach ($book->chapters as $thisChapter) {
$discoveredChapterTitles[] = $thisChapter->name;
}
$this->assertTrue(in_array('First chapter A', $discoveredChapterTitles));
$this->assertTrue(in_array('Second chapter B', $discoveredChapterTitles));
$this->assertEquals('First chapter A', $book->chapters[0]->name);
$this->assertEquals('Second chapter B', $book->chapters[1]->name);
}

public function testReplacementOfIdentifiedEmbedManyElements()
{
$book = new GH1141Book();
$book->identifiedChapters->add(new GH1141IdentifiedChapter('A'));

$this->dm->persist($book);
$this->dm->flush();
$this->dm->clear();

$book = $this->dm->getRepository(GH1141Book::CLASSNAME)->findOneBy(array('_id' => $book->id));
$firstChapter = $book->identifiedChapters->first();
$firstChapter->name = "First chapter A";
$replacementChapters = new ArrayCollection();
$replacementChapters->add($firstChapter);
$replacementChapters->add(new GH1141IdentifiedChapter('Second chapter B'));
$book->identifiedChapters = $replacementChapters;

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

$book = $this->dm->getRepository(GH1141Book::CLASSNAME)->findOneBy(array('_id' => $book->id));
$this->assertEquals('First chapter A', $book->identifiedChapters[0]->name);
$this->assertEquals('Second chapter B', $book->identifiedChapters[1]->name);
}
}

Expand All @@ -57,9 +78,13 @@ class GH1141Book
/** @ODM\EmbedMany(targetDocument="GH1141Chapter", strategy="atomicSet") */
public $chapters;

/** @ODM\EmbedMany(targetDocument="GH1141IdentifiedChapter", strategy="atomicSet") */
public $identifiedChapters;

public function __construct()
{
$this->chapters = new ArrayCollection();
$this->identifiedChapters = new ArrayCollection();
}
}

Expand All @@ -74,3 +99,18 @@ public function __construct($name)
$this->name = $name;
}
}

/** @ODM\EmbeddedDocument */
class GH1141IdentifiedChapter
{
/** @ODM\Id */
public $id;

/** @ODM\String */
public $name;

public function __construct($name)
{
$this->name = $name;
}
}

0 comments on commit 74db05f

Please sign in to comment.