Permalink
Browse files

Add test for DDC-1436 and DDC-1452 showing they are the same issues

  • Loading branch information...
1 parent 43b1e79 commit 2187f334777314548e582a4d20425b3ac60b7b6b @beberlei beberlei committed Nov 18, 2011
Showing with 89 additions and 0 deletions.
  1. +89 −0 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1436Test.php
@@ -0,0 +1,89 @@
+<?php
+
+namespace Doctrine\Tests\ORM\Functional\Ticket;
+use Doctrine\ORM\UnitOfWork;
+
+/**
+ * @group DDC-1436
+ */
+class DDC1436Test extends \Doctrine\Tests\OrmFunctionalTestCase
+{
+ protected function setUp()
+ {
+ parent::setUp();
+
+ try {
+ $this->_schemaTool->createSchema(array(
+ $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1436Page'),
+ ));
+ } catch (\Exception $ignored) {
+ }
+ }
+
+ public function testIdentityMap()
+ {
+ // fixtures
+ $parent = null;
+ for ($i = 0; $i < 3; $i++) {
+ $page = new DDC1436Page();
+ $page->setParent($parent);
+ $this->_em->persist($page);
+ $parent = $page;
+ }
+ $this->_em->flush();
+ $this->_em->clear();
+
+ $id = $parent->getId();
+
+ // step 1
+ $page = $this->_em
+ ->createQuery('SELECT p, parent FROM ' . __NAMESPACE__ . '\DDC1436Page p LEFT JOIN p.parent parent WHERE p.id = :id')
+ ->setParameter('id', $id)
+ ->getOneOrNullResult();
+
+ $this->assertInstanceOf(__NAMESPACE__ . '\DDC1436Page', $page);
+
+ // step 2
+ $page = $this->_em->find(__NAMESPACE__ . '\DDC1436Page', $id);
+ $this->assertInstanceOf(__NAMESPACE__ . '\DDC1436Page', $page);
+ $this->assertInstanceOf(__NAMESPACE__ . '\DDC1436Page', $page->getParent());
+ $this->assertInstanceOf(__NAMESPACE__ . '\DDC1436Page', $page->getParent()->getParent());
+ }
+}
+
+/**
+ * @Entity
+ */
+class DDC1436Page
+{
+ /**
+ * @Id
+ * @GeneratedValue
+ * @Column(type="integer", name="id")
+ */
+ protected $id;
+ /**
+ * @ManyToOne(targetEntity="DDC1436Page")
+ * @JoinColumn(name="pid", referencedColumnName="id")
+ */
+ protected $parent;
+
+ public function getId()
+ {
+ return $this->id;
+ }
+
+ /**
+ * @return DDC1436Page
+ */
+ public function getParent()
+ {
+ return $this->parent;
+ }
+
+ public function setParent($parent)
+ {
+ $this->parent = $parent;
+ }
+}
+

0 comments on commit 2187f33

Please sign in to comment.