123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317 |
- <?php
- namespace Doctrine\Tests\ORM\Functional\Ticket;
- require_once __DIR__ . '/../../../TestInit.php';
- /**
- * @group DDC-1080
- */
- class DDC1080Test extends \Doctrine\Tests\OrmFunctionalTestCase
- {
- public function testHydration()
- {
- $this->_schemaTool->createSchema(array(
- $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1080Foo'),
- $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1080Bar'),
- $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC1080FooBar'),
- ));
- $foo1 = new DDC1080Foo();
- $foo1->setFooTitle('foo title 1');
- $foo2 = new DDC1080Foo();
- $foo2->setFooTitle('foo title 2');
- $bar1 = new DDC1080Bar();
- $bar1->setBarTitle('bar title 1');
- $bar2 = new DDC1080Bar();
- $bar2->setBarTitle('bar title 2');
- $bar3 = new DDC1080Bar();
- $bar3->setBarTitle('bar title 3');
- $foobar1 = new DDC1080FooBar();
- $foobar1->setFoo($foo1);
- $foobar1->setBar($bar1);
- $foobar1->setOrderNr(0);
- $foobar2 = new DDC1080FooBar();
- $foobar2->setFoo($foo1);
- $foobar2->setBar($bar2);
- $foobar2->setOrderNr(0);
- $foobar3 = new DDC1080FooBar();
- $foobar3->setFoo($foo1);
- $foobar3->setBar($bar3);
- $foobar3->setOrderNr(0);
- $this->_em->persist($foo1);
- $this->_em->persist($foo2);
- $this->_em->persist($bar1);
- $this->_em->persist($bar2);
- $this->_em->persist($bar3);
- $this->_em->flush();
- $this->_em->persist($foobar1);
- $this->_em->persist($foobar2);
- $this->_em->persist($foobar3);
- $this->_em->flush();
- $this->_em->clear();
- $foo = $this->_em->find('Doctrine\Tests\ORM\Functional\Ticket\DDC1080Foo', $foo1->getFooId());
- $fooBars = $foo->getFooBars();
- $this->assertEquals(3, count($fooBars), "Should return three foobars.");
- }
- }
- /**
- * @Entity
- * @Table(name="foo")
- */
- class DDC1080Foo
- {
- /**
- * @Id
- * @Column(name="fooID", type="integer")
- * @GeneratedValue(strategy="AUTO")
- */
- protected $_fooID;
- /**
- * @Column(name="fooTitle", type="string")
- */
- protected $_fooTitle;
- /**
- * @OneToMany(targetEntity="DDC1080FooBar", mappedBy="_foo",
- * cascade={"persist"})
- * @OrderBy({"_orderNr"="ASC"})
- */
- protected $_fooBars;
- public function __construct()
- {
- $this->_fooBars = new \Doctrine\Common\Collections\ArrayCollection();
- }
- /**
- * @return the $fooID
- */
- public function getFooID()
- {
- return $this->_fooID;
- }
- /**
- * @return the $fooTitle
- */
- public function getFooTitle()
- {
- return $this->_fooTitle;
- }
- /**
- * @return the $fooBars
- */
- public function getFooBars()
- {
- return $this->_fooBars;
- }
- /**
- * @param field_type $fooID
- */
- public function setFooID($fooID)
- {
- $this->_fooID = $fooID;
- }
- /**
- * @param field_type $fooTitle
- */
- public function setFooTitle($fooTitle)
- {
- $this->_fooTitle = $fooTitle;
- }
- /**
- * @param field_type $fooBars
- */
- public function setFooBars($fooBars)
- {
- $this->_fooBars = $fooBars;
- }
- }
- /**
- * @Entity
- * @Table(name="bar")
- */
- class DDC1080Bar
- {
- /**
- * @Id
- * @Column(name="barID", type="integer")
- * @GeneratedValue(strategy="AUTO")
- */
- protected $_barID;
- /**
- * @Column(name="barTitle", type="string")
- */
- protected $_barTitle;
- /**
- * @OneToMany(targetEntity="DDC1080FooBar", mappedBy="_bar",
- * cascade={"persist"})
- * @OrderBy({"_orderNr"="ASC"})
- */
- protected $_fooBars;
- public function __construct()
- {
- $this->_fooBars = new \Doctrine\Common\Collections\ArrayCollection();
- }
- /**
- * @return the $barID
- */
- public function getBarID()
- {
- return $this->_barID;
- }
- /**
- * @return the $barTitle
- */
- public function getBarTitle()
- {
- return $this->_barTitle;
- }
- /**
- * @return the $fooBars
- */
- public function getFooBars()
- {
- return $this->_fooBars;
- }
- /**
- * @param field_type $barID
- */
- public function setBarID($barID)
- {
- $this->_barID = $barID;
- }
- /**
- * @param field_type $barTitle
- */
- public function setBarTitle($barTitle)
- {
- $this->_barTitle = $barTitle;
- }
- /**
- * @param field_type $fooBars
- */
- public function setFooBars($fooBars)
- {
- $this->_fooBars = $fooBars;
- }
- }
- /**
- * @Table(name="fooBar")
- * @Entity
- */
- class DDC1080FooBar
- {
- /**
- * @ManyToOne(targetEntity="DDC1080Foo")
- * @JoinColumn(name="fooID", referencedColumnName="fooID")
- * @Id
- */
- protected $_foo = null;
- /**
- * @ManyToOne(targetEntity="DDC1080Bar")
- * @JoinColumn(name="barID", referencedColumnName="barID")
- * @Id
- */
- protected $_bar = null;
- /**
- * @var integer orderNr
- * @Column(name="orderNr", type="integer", nullable=false)
- */
- protected $_orderNr = null;
- /**
- * Retrieve the foo property
- *
- * @return DDC1080Foo
- */
- public function getFoo()
- {
- return $this->_foo;
- }
- /**
- * Set the foo property
- *
- * @param DDC1080Foo $foo
- * @return DDC1080FooBar
- */
- public function setFoo($foo)
- {
- $this->_foo = $foo;
- return $this;
- }
- /**
- * Retrieve the bar property
- *
- * @return DDC1080Bar
- */
- public function getBar()
- {
- return $this->_bar;
- }
- /**
- * Set the bar property
- *
- * @param DDC1080Bar $bar
- * @return DDC1080FooBar
- */
- public function setBar($bar)
- {
- $this->_bar = $bar;
- return $this;
- }
- /**
- * Retrieve the orderNr property
- *
- * @return integer|null
- */
- public function getOrderNr()
- {
- return $this->_orderNr;
- }
- /**
- * Set the orderNr property
- *
- * @param integer|null $orderNr
- * @return DDC1080FooBar
- */
- public function setOrderNr($orderNr)
- {
- $this->_orderNr = $orderNr;
- return $this;
- }
- }
|