X-Git-Url: http://git.inspyration.org/?a=blobdiff_plain;f=vendor%2Fdoctrine%2Form%2Ftests%2FDoctrine%2FTests%2FORM%2FFunctional%2FPersistentCollectionTest.php;fp=vendor%2Fdoctrine%2Form%2Ftests%2FDoctrine%2FTests%2FORM%2FFunctional%2FPersistentCollectionTest.php;h=2125966fce3aa1c9fc4ed82403f7e35a54f278bc;hb=8b04b2d11798dee4f3e1358e4f43e97a6df851f6;hp=0000000000000000000000000000000000000000;hpb=73568cf05a785a45f94ca3f2351d9e07bf917958;p=zf2.biz%2Fgalerie.git diff --git a/vendor/doctrine/orm/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionTest.php b/vendor/doctrine/orm/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionTest.php new file mode 100644 index 0000000..2125966 --- /dev/null +++ b/vendor/doctrine/orm/tests/Doctrine/Tests/ORM/Functional/PersistentCollectionTest.php @@ -0,0 +1,98 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\PersistentCollectionHolder'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\PersistentCollectionContent'), + )); + } catch (\Exception $e) { + + } + PersistentObject::setObjectManager($this->_em); + } + + public function testPersist() + { + $collectionHolder = new PersistentCollectionHolder(); + $content = new PersistentCollectionContent('first element'); + $collectionHolder->addElement($content); + + $this->_em->persist($collectionHolder); + $this->_em->flush(); + $this->_em->clear(); + + $collectionHolder = $this->_em->find(__NAMESPACE__ . '\PersistentCollectionHolder', $collectionHolder->getId()); + $collectionHolder->getCollection(); + + $content = new PersistentCollectionContent('second element'); + $collectionHolder->addElement($content); + + $this->assertEquals(2, $collectionHolder->getCollection()->count()); + } + +} + +/** + * @Entity + */ +class PersistentCollectionHolder extends PersistentObject +{ + /** + * @Id @Column(type="integer") @GeneratedValue + * @var int + */ + protected $id; + + /** + * @var \Doctrine\Common\Collections\Collection + * @ManyToMany(targetEntity="PersistentCollectionContent", cascade={"all"}) + */ + protected $collection; + + public function __construct() + { + $this->collection = new \Doctrine\Common\Collections\ArrayCollection(); + } + + /** + * @param PersistentCollectionContent $element + */ + public function addElement(PersistentCollectionContent $element) + { + $this->collection->add($element); + } + + /** + * @return \Doctrine\Common\Collections\Collection + */ + public function getCollection() + { + return clone $this->collection; + } + +} + +/** + * @Entity + */ +class PersistentCollectionContent extends PersistentObject +{ + + /** + * @Id @Column(type="integer") @GeneratedValue + * @var int + */ + protected $id; + +}