3 namespace Doctrine\Tests\ORM\Functional\Ticket;
10 class DDC1655Test extends \Doctrine\Tests\OrmFunctionalTestCase
12 public function setUp()
16 $this->_schemaTool->createSchema(array(
17 $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1655Foo'),
18 $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1655Bar'),
19 $this->_em->getClassMetadata(__NAMESPACE__ . '\\DDC1655Baz'),
21 } catch(\Exception $e) {
26 public function testPostLoadOneToManyInheritance()
28 $cm = $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1655Foo');
29 $this->assertEquals(array("postLoad" => array("postLoad")), $cm->lifecycleCallbacks);
31 $cm = $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1655Bar');
32 $this->assertEquals(array("postLoad" => array("postLoad", "postSubLoaded")), $cm->lifecycleCallbacks);
34 $baz = new DDC1655Baz();
35 $foo = new DDC1655Foo();
37 $bar = new DDC1655Bar();
40 $this->_em->persist($foo);
41 $this->_em->persist($bar);
42 $this->_em->persist($baz);
46 $baz = $this->_em->find(get_class($baz), $baz->id);
47 foreach ($baz->foos as $foo) {
48 $this->assertEquals(1, $foo->loaded, "should have loaded callback counter incremented for " . get_class($foo));
53 * Check that post load is not executed several times when the entity
54 * is rehydrated again although its already known.
56 public function testPostLoadInheritanceChild()
58 $bar = new DDC1655Bar();
60 $this->_em->persist($bar);
64 $bar = $this->_em->find(get_class($bar), $bar->id);
65 $this->assertEquals(1, $bar->loaded);
66 $this->assertEquals(1, $bar->subLoaded);
68 $bar = $this->_em->find(get_class($bar), $bar->id);
69 $this->assertEquals(1, $bar->loaded);
70 $this->assertEquals(1, $bar->subLoaded);
72 $dql = "SELECT b FROM " . __NAMESPACE__ . "\DDC1655Bar b WHERE b.id = ?1";
73 $bar = $this->_em->createQuery($dql)->setParameter(1, $bar->id)->getSingleResult();
75 $this->assertEquals(1, $bar->loaded);
76 $this->assertEquals(1, $bar->subLoaded);
78 $this->_em->refresh($bar);
80 $this->assertEquals(2, $bar->loaded);
81 $this->assertEquals(2, $bar->subLoaded);
87 * @InheritanceType("SINGLE_TABLE")
89 * "foo" = "DDC1655Foo",
90 * "bar" = "DDC1655Bar"
92 * @HasLifecycleCallbacks
96 /** @Id @GeneratedValue @Column(type="integer") */
102 * @ManyToOne(targetEntity="DDC1655Baz", inversedBy="foos")
109 public function postLoad()
117 * @HasLifecycleCallbacks
119 class DDC1655Bar extends DDC1655Foo
126 public function postSubLoaded()
137 /** @Id @GeneratedValue @Column(type="integer") */
141 * @OneToMany(targetEntity="DDC1655Foo", mappedBy="baz")
143 public $foos = array();