Created
January 9, 2017 12:54
-
-
Save redthor/ce6ef962439775afb9afb3897ffa4a61 to your computer and use it in GitHub Desktop.
GH1525Test with ID strategy NONE on parent
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
<?php | |
namespace Doctrine\ODM\MongoDB\Tests\Functional\Ticket; | |
use Doctrine\Common\Collections\ArrayCollection; | |
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM; | |
class GH1525Test extends \Doctrine\ODM\MongoDB\Tests\BaseTest | |
{ | |
public function testEmbedClone() | |
{ | |
$embedded = new GH1525Embedded('embedded'); | |
$count = 2; | |
for ($i = 0; $i < $count; ++$i) { | |
$parent = new GH1525Document('test' . $i); | |
$parent->embedded = $embedded; | |
$this->dm->persist($parent); | |
$this->dm->flush(); | |
} | |
$this->dm->clear(); | |
for ($i = 0; $i < $count; ++$i) { | |
$test = $this->dm->getRepository(GH1525Document::class)->findOneBy(array('name' => 'test' . $i)); | |
$this->assertInstanceOf(GH1525Document::class, $test); | |
$this->assertInstanceOf(GH1525Embedded::class, $test->embedded); | |
$this->assertSame($test->embedded->name, $embedded->name); | |
} | |
} | |
public function testEmbedCloneWithIdStrategyNoneOnParent() | |
{ | |
$uuidGen = new \Doctrine\ODM\MongoDB\Id\UuidGenerator(); | |
$embedded = new GH1525Embedded('embedded'); | |
$count = 2; | |
for ($i = 0; $i < $count; ++$i) { | |
$parent = new GH1525DocumentIdStrategyNone($uuidGen->generateV4(), 'test' . $i); | |
$parent->embedded = $embedded; | |
$this->dm->persist($parent); | |
$this->dm->flush(); | |
} | |
$this->dm->clear(); | |
for ($i = 0; $i < $count; ++$i) { | |
$test = $this->dm->getRepository(GH1525DocumentIdStrategyNone::class)->findOneBy(array('name' => 'test' . $i)); | |
$this->assertInstanceOf(GH1525DocumentIdStrategyNone::class, $test); | |
$this->assertInstanceOf(GH1525Embedded::class, $test->embedded); | |
$this->assertSame($test->embedded->name, $embedded->name); | |
} | |
} | |
} | |
/** @ODM\Document(collection="document_test") */ | |
class GH1525Document | |
{ | |
/** @ODM\Id */ | |
public $id; | |
/** @ODM\Field(type="string") */ | |
public $name; | |
/** @ODM\EmbedOne(targetDocument="GH1525Embedded") */ | |
public $embedded; | |
public function __construct($name) | |
{ | |
$this->name = $name; | |
} | |
} | |
/** @ODM\Document(collection="document_test_with_auto_ids") */ | |
class GH1525DocumentIdStrategyNone | |
{ | |
/** @ODM\Id(strategy="NONE") */ | |
public $id; | |
/** @ODM\Field(type="string") */ | |
public $name; | |
/** @ODM\EmbedOne(targetDocument="GH1525Embedded") */ | |
public $embedded; | |
public function __construct($id, $name) | |
{ | |
$this->id = $id; | |
$this->name = $name; | |
} | |
} | |
/** @ODM\EmbeddedDocument */ | |
class GH1525Embedded | |
{ | |
/** @ODM\Field(type="string") */ | |
public $name; | |
public function __construct($name) | |
{ | |
$this->name = $name; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment