From 6afcac84d07ac076d4d9eb382a819877551c65d9 Mon Sep 17 00:00:00 2001 From: vvh-empora Date: Tue, 3 Mar 2015 11:40:19 +0100 Subject: [PATCH 1/3] embeddedClasses support... ...for JoinedSubclassPersister.php --- lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php index d4159ce47..2886413fd 100644 --- a/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/Entity/JoinedSubclassPersister.php @@ -546,7 +546,8 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister if (isset($this->class->fieldMappings[$name]['inherited']) && ! isset($this->class->fieldMappings[$name]['id']) || isset($this->class->associationMappings[$name]['inherited']) - || ($this->class->isVersioned && $this->class->versionField == $name)) { + || ($this->class->isVersioned && $this->class->versionField == $name) + || isset($this->class->embeddedClasses[$name])) { continue; } From 2aef87c9b2e54d6287fcb3232365a47fd753f200 Mon Sep 17 00:00:00 2001 From: Volker von Hoesslin Date: Tue, 3 Mar 2015 16:59:48 +0100 Subject: [PATCH 2/3] add unittest for DDC3597 --- .../Tests/Models/DDC3597/DDC3597Image.php | 35 +++++++++ .../Tests/Models/DDC3597/DDC3597Media.php | 74 ++++++++++++++++++ .../Tests/Models/DDC3597/DDC3597Root.php | 78 +++++++++++++++++++ .../DDC3597/Embeddable/DDC3597Dimension.php | 56 +++++++++++++ .../ORM/Functional/Ticket/DDC3597Test.php | 54 +++++++++++++ 5 files changed, 297 insertions(+) create mode 100644 tests/Doctrine/Tests/Models/DDC3597/DDC3597Image.php create mode 100644 tests/Doctrine/Tests/Models/DDC3597/DDC3597Media.php create mode 100644 tests/Doctrine/Tests/Models/DDC3597/DDC3597Root.php create mode 100644 tests/Doctrine/Tests/Models/DDC3597/Embeddable/DDC3597Dimension.php create mode 100644 tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3597Test.php diff --git a/tests/Doctrine/Tests/Models/DDC3597/DDC3597Image.php b/tests/Doctrine/Tests/Models/DDC3597/DDC3597Image.php new file mode 100644 index 000000000..fcc905e90 --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC3597/DDC3597Image.php @@ -0,0 +1,35 @@ + + * @Entity + */ +class DDC3597Image extends DDC3597Media { + + /** + * @var DDC3597Dimension + * @Embedded(class = "Doctrine\Tests\Models\DDC3597\Embeddable\DDC3597Dimension", columnPrefix = false) + */ + private $dimension; + + /** + * @param string $distributionHash + */ + function __construct($distributionHash) { + parent::__construct($distributionHash); + $this->dimension = new DDC3597Dimension(); + } + + /** + * @return DDC3597Dimension + */ + public function getDimension() { + return $this->dimension; + } +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/Models/DDC3597/DDC3597Media.php b/tests/Doctrine/Tests/Models/DDC3597/DDC3597Media.php new file mode 100644 index 000000000..07872431b --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC3597/DDC3597Media.php @@ -0,0 +1,74 @@ + + * @Entity + */ +abstract class DDC3597Media extends DDC3597Root { + + /** + * @var string + * + * @Column + */ + private $distributionHash; + + /** + * @var integer + * + * @Column + */ + private $size = 0; + + /** + * @var string + * @Column + */ + private $format; + + function __construct($distributionHash) { + $this->distributionHash = $distributionHash; + } + + /** + * @return string + */ + public function getDistributionHash() { + return $this->distributionHash; + } + + /** + * @return int + */ + public function getSize() { + return $this->size; + } + + /** + * @param int $size + */ + public function setSize($size) { + $this->size = $size; + } + + /** + * @return string + */ + public function getFormat() { + return $this->format; + } + + /** + * @param string $format + */ + public function setFormat($format) { + $this->format = $format; + } + + + +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/Models/DDC3597/DDC3597Root.php b/tests/Doctrine/Tests/Models/DDC3597/DDC3597Root.php new file mode 100644 index 000000000..8c8228d5d --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC3597/DDC3597Root.php @@ -0,0 +1,78 @@ +updatedAt = $this->createdAt = new \DateTime(); + } + + /** + * Set updatedAt + * + * @PreUpdate + */ + public function _preUpdate() { + $this->updatedAt = new \DateTime(); + } + + /** + * @return int + */ + public function getId() { + return (int)$this->id; + } + + + /** + * @return \DateTime + */ + public function getCreatedAt() { + return $this->createdAt; + } + + /** + * @return \DateTime + */ + public function getUpdatedAt() { + return $this->updatedAt; + } +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/Models/DDC3597/Embeddable/DDC3597Dimension.php b/tests/Doctrine/Tests/Models/DDC3597/Embeddable/DDC3597Dimension.php new file mode 100644 index 000000000..cd5dc70a2 --- /dev/null +++ b/tests/Doctrine/Tests/Models/DDC3597/Embeddable/DDC3597Dimension.php @@ -0,0 +1,56 @@ +setWidth($width); + $this->setHeight($height); + } + + /** + * @return int + */ + public function getWidth() { + return $this->width; + } + + /** + * @param int $width + */ + public function setWidth($width) { + $this->width = (int)$width; + } + + /** + * @return int + */ + public function getHeight() { + return $this->height; + } + + /** + * @param int $height + */ + public function setHeight($height) { + $this->height = (int)$height; + } +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3597Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3597Test.php new file mode 100644 index 000000000..65425184d --- /dev/null +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3597Test.php @@ -0,0 +1,54 @@ +_schemaTool->createSchema(array( + $this->_em->getClassMetadata(DDC3597Root::class), + $this->_em->getClassMetadata(DDC3597Media::class), + $this->_em->getClassMetadata(DDC3597Image::class) + )); + } + + /** + * @group DDC-3597 + */ + public function testSaveImageEntity() { + $imageEntity = new DDC3597Image('foobar'); + $imageEntity->setFormat('JPG'); + $imageEntity->setSize(123); + $imageEntity->getDimension()->setWidth(300); + $imageEntity->getDimension()->setHeight(500); + + $this->_em->persist($imageEntity); + $this->_em->flush(); //before this fix, it will fail with a exception + + $this->_em->clear(); + + //request entity + $imageEntity = $this->_em->find(DDC3597Image::class, $imageEntity->getId()); + $this->assertInstanceOf(DDC3597Image::class, $imageEntity); + + //cleanup + $this->_em->remove($imageEntity); + $this->_em->flush(); + $this->_em->clear(); + + //check delete + $imageEntity = $this->_em->find(DDC3597Image::class, $imageEntity->getId()); + $this->assertNull($imageEntity); + } + +} From 0824c6136d064211761a4b409ada639a184f6cd9 Mon Sep 17 00:00:00 2001 From: Volker von Hoesslin Date: Wed, 4 Mar 2015 11:55:08 +0100 Subject: [PATCH 3/3] unittest DDC3597: fix for PHP 5.4 --- .../Tests/Models/DDC3597/DDC3597Image.php | 2 ++ .../Tests/Models/DDC3597/DDC3597Media.php | 2 ++ .../Tests/Models/DDC3597/DDC3597Root.php | 2 ++ .../ORM/Functional/Ticket/DDC3597Test.php | 23 ++++++++----------- 4 files changed, 16 insertions(+), 13 deletions(-) diff --git a/tests/Doctrine/Tests/Models/DDC3597/DDC3597Image.php b/tests/Doctrine/Tests/Models/DDC3597/DDC3597Image.php index fcc905e90..2254b4243 100644 --- a/tests/Doctrine/Tests/Models/DDC3597/DDC3597Image.php +++ b/tests/Doctrine/Tests/Models/DDC3597/DDC3597Image.php @@ -12,6 +12,8 @@ use Doctrine\Tests\Models\DDC3597\Embeddable\DDC3597Dimension; */ class DDC3597Image extends DDC3597Media { + const CLASSNAME = __CLASS__; + /** * @var DDC3597Dimension * @Embedded(class = "Doctrine\Tests\Models\DDC3597\Embeddable\DDC3597Dimension", columnPrefix = false) diff --git a/tests/Doctrine/Tests/Models/DDC3597/DDC3597Media.php b/tests/Doctrine/Tests/Models/DDC3597/DDC3597Media.php index 07872431b..751f7dac1 100644 --- a/tests/Doctrine/Tests/Models/DDC3597/DDC3597Media.php +++ b/tests/Doctrine/Tests/Models/DDC3597/DDC3597Media.php @@ -10,6 +10,8 @@ namespace Doctrine\Tests\Models\DDC3597; */ abstract class DDC3597Media extends DDC3597Root { + const CLASSNAME = __CLASS__; + /** * @var string * diff --git a/tests/Doctrine/Tests/Models/DDC3597/DDC3597Root.php b/tests/Doctrine/Tests/Models/DDC3597/DDC3597Root.php index 8c8228d5d..d7f86dfba 100644 --- a/tests/Doctrine/Tests/Models/DDC3597/DDC3597Root.php +++ b/tests/Doctrine/Tests/Models/DDC3597/DDC3597Root.php @@ -15,6 +15,8 @@ use Doctrine\ORM\Mapping\DiscriminatorMap; */ abstract class DDC3597Root { + const CLASSNAME = __CLASS__; + /** * @var int * diff --git a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3597Test.php b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3597Test.php index 65425184d..e6f25b852 100644 --- a/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3597Test.php +++ b/tests/Doctrine/Tests/ORM/Functional/Ticket/DDC3597Test.php @@ -2,23 +2,21 @@ namespace Doctrine\Tests\ORM\Functional\Ticket; -use Doctrine\Tests\Models\DDC3597\DDC3597Root; -use Doctrine\Tests\Models\DDC3597\DDC3597Media; use Doctrine\Tests\Models\DDC3597\DDC3597Image; +use Doctrine\Tests\Models\DDC3597\DDC3597Media; +use Doctrine\Tests\Models\DDC3597\DDC3597Root; /** * @group DDC-117 */ -class DDC3597Test extends \Doctrine\Tests\OrmFunctionalTestCase -{ +class DDC3597Test extends \Doctrine\Tests\OrmFunctionalTestCase { - protected function setUp() - { + protected function setUp() { parent::setUp(); $this->_schemaTool->createSchema(array( - $this->_em->getClassMetadata(DDC3597Root::class), - $this->_em->getClassMetadata(DDC3597Media::class), - $this->_em->getClassMetadata(DDC3597Image::class) + $this->_em->getClassMetadata(DDC3597Root::CLASSNAME), + $this->_em->getClassMetadata(DDC3597Media::CLASSNAME), + $this->_em->getClassMetadata(DDC3597Image::CLASSNAME) )); } @@ -38,8 +36,8 @@ class DDC3597Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->clear(); //request entity - $imageEntity = $this->_em->find(DDC3597Image::class, $imageEntity->getId()); - $this->assertInstanceOf(DDC3597Image::class, $imageEntity); + $imageEntity = $this->_em->find(DDC3597Image::CLASSNAME, $imageEntity->getId()); + $this->assertInstanceOf(DDC3597Image::CLASSNAME, $imageEntity); //cleanup $this->_em->remove($imageEntity); @@ -47,8 +45,7 @@ class DDC3597Test extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->clear(); //check delete - $imageEntity = $this->_em->find(DDC3597Image::class, $imageEntity->getId()); + $imageEntity = $this->_em->find(DDC3597Image::CLASSNAME, $imageEntity->getId()); $this->assertNull($imageEntity); } - }