From b3d0ad7a87026445525b3dd6722abfc03852ac82 Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Wed, 31 Jul 2013 01:24:02 -0400 Subject: [PATCH] Added coverage to DDC-2524. Updated DDC-1719 to fix related DBAL bug. --- .../ORM/Functional/Ticket/DDC1719Test.php | 22 ++- .../ORM/Functional/Ticket/DDC2524Test.php | 148 ++++++++++++++++++ 2 files changed, 162 insertions(+), 8 deletions(-) create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2524Test.php diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1719Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1719Test.php index 8ea93a9ec..93130f56b 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1719Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC1719Test.php @@ -11,18 +11,24 @@ require_once __DIR__ . '/../../../TestInit.php'; */ class DDC1719Test extends \Doctrine\Tests\OrmFunctionalTestCase { - - const CLASS_NAME = '\Doctrine\Tests\Models\Quote\SimpleEntity'; + const CLASS_NAME = 'Doctrine\Tests\Models\Quote\SimpleEntity'; protected function setUp() { parent::setUp(); - try { - $this->_schemaTool->createSchema(array( - $this->_em->getClassMetadata(self::CLASS_NAME), - )); - } catch(\Exception $e) { - } + + $this->_schemaTool->createSchema(array( + $this->_em->getClassMetadata(self::CLASS_NAME), + )); + } + + protected function tearDown() + { + parent::tearDown(); + + $this->_schemaTool->dropSchema(array( + $this->_em->getClassMetadata(self::CLASS_NAME), + )); } public function testCreateRetrieveUpdateDelete() diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2524Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2524Test.php new file mode 100644 index 000000000..c5a7cad70 --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC2524Test.php @@ -0,0 +1,148 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2524EntityO'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2524EntityG'), + )); + } + + protected function tearDown() + { + parent::tearDown(); + + $this->_schemaTool->dropSchema(array( + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2524EntityO'), + $this->_em->getClassMetadata(__NAMESPACE__ . '\DDC2524EntityG'), + )); + } + + public function testSingle() + { + $eO = new DDC2524EntityO(); + $eG = new DDC2524EntityG($eO); + + $this->_em->persist($eO); + $this->_em->flush(); + $this->_em->clear(); + + $eOloaded = $this->_em->find(__NAMESPACE__ . '\DDC2524EntityO', $eO->getId()); + + $this->_em->remove($eOloaded); + $this->_em->flush(); + } + + public function testMany() + { + $eO = new DDC2524EntityO(); + $eG1 = new DDC2524EntityG($eO); + $eG2 = new DDC2524EntityG($eO); + $eG3 = new DDC2524EntityG($eO); + + $eO->setOneToOneG($eG2); + + $this->_em->persist($eO); + $this->_em->flush(); + $this->_em->clear(); + + $eOloaded = $this->_em->find(__NAMESPACE__ . '\DDC2524EntityO', $eO->getId()); + + $this->_em->remove($eOloaded); + $this->_em->flush(); + } +} + +/** + * @Entity + */ +class DDC2524EntityO +{ + /** + * @Id @Column(type="integer") + * @GeneratedValue + */ + private $id; + + /** + * @OneToOne(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\DDC2524EntityG") + * @JoinColmun(nullable=true) + **/ + private $oneToOneG; + + /** + * @OneToMany(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\DDC2524EntityG", mappedBy="ownerO", cascade={"persist", "remove"}) + **/ + private $oneToManyG; + + public function __construct() + { + $this->oneToManyG = new ArrayCollection(); + } + + public function getId() + { + return $this->id; + } + + public function setOneToOneG(DDC2524EntityG $eG) + { + $this->oneToOneG = $eG; + } + + public function getOneToOneG() + { + return $this->oneToOneG; + } + + public function addOneToManyG(DDC2524EntityG $eG) + { + $this->oneToManyG->add($eG); + } + + public function getOneToManyGs() + { + return $this->oneToManyG->toArray(); + } +} + +/** + * @Entity + */ +class DDC2524EntityG +{ + /** + * @Id @Column(type="integer") + * @GeneratedValue + */ + private $id; + + /** + * @ManyToOne(targetEntity="Doctrine\Tests\ORM\Functional\Ticket\DDC2524EntityO", inversedBy="oneToManyG") + **/ + private $ownerO; + + public function __construct(DDC2524EntityO $eO, $position = 1) + { + $this->position = $position; + $this->ownerO = $eO; + + $this->ownerO->addOneToManyG($this); + } + + public function getId() + { + return $this->id; + } +}