3 namespace Doctrine\Tests\ORM\Functional\Ticket;
5 require_once __DIR__ . '/../../../TestInit.php';
7 class DDC729Test extends \Doctrine\Tests\OrmFunctionalTestCase
9 public function setUp()
14 $schemaTool = new \Doctrine\ORM\Tools\SchemaTool($this->_em);
15 $schemaTool->createSchema(array(
16 $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC729A'),
17 $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC729B'),
19 } catch(\Exception $e) {
24 public function testMergeManyToMany()
30 $this->_em->persist($a);
31 $this->_em->persist($b);
39 $this->assertInstanceOf('Doctrine\Common\Collections\ArrayCollection', $a->related);
41 $a = $this->_em->merge($a);
43 $this->assertInstanceOf('Doctrine\ORM\PersistentCollection', $a->related);
45 $this->assertFalse($a->related->isInitialized(), "Collection should not be marked initialized.");
46 $this->assertFalse($a->related->isDirty(), "Collection should not be marked as dirty.");
51 $a = $this->_em->find(__NAMESPACE__ . '\DDC729A', $aId);
52 $this->assertEquals(1, count($a->related));
55 public function testUnidirectionalMergeManyToMany()
62 $this->_em->persist($a);
63 $this->_em->persist($b1);
64 $this->_em->persist($b2);
72 $a = $this->_em->merge($a);
74 $a->related->set(0, $this->_em->merge($b1));
76 $a->related->set(1, $this->_em->merge($b2));
81 $a = $this->_em->find(__NAMESPACE__ . '\DDC729A', $aId);
82 $this->assertEquals(2, count($a->related));
85 public function testBidirectionalMergeManyToMany()
92 $this->_em->persist($a);
93 $this->_em->persist($b1);
94 $this->_em->persist($b2);
102 $a = $this->_em->merge($a);
104 $a->related->set(0, $this->_em->merge($b1));
105 $b1->related->set(0, $a);
107 $a->related->set(1, $this->_em->merge($b2));
108 $b2->related->set(0, $a);
113 $a = $this->_em->find(__NAMESPACE__ . '\DDC729A', $aId);
114 $this->assertEquals(2, count($a->related));
117 public function testBidirectionalMultiMergeManyToMany()
124 $this->_em->persist($a);
125 $this->_em->persist($b1);
126 $this->_em->persist($b2);
134 $a = $this->_em->merge($a);
136 $a->related->set(0, $this->_em->merge($b1));
137 $b1->related->set(0, $this->_em->merge($a));
139 $a->related->set(1, $this->_em->merge($b2));
140 $b2->related->set(0, $this->_em->merge($a));
145 $a = $this->_em->find(__NAMESPACE__ . '\DDC729A', $aId);
146 $this->assertEquals(2, count($a->related));
155 /** @Id @GeneratedValue @Column(type="integer") */
158 /** @ManyToMany(targetEntity="DDC729B", inversedBy="related") */
161 public function __construct()
163 $this->related = new \Doctrine\Common\Collections\ArrayCollection();
172 /** @Id @GeneratedValue @Column(type="integer") */
175 /** @ManyToMany(targetEntity="DDC729B", mappedBy="related") */
178 public function __construct()
180 $this->related = new \Doctrine\Common\Collections\ArrayCollection();