1
0
mirror of synced 2024-12-05 03:06:05 +03:00

add unittest for DDC3597

This commit is contained in:
Volker von Hoesslin 2015-03-03 16:59:48 +01:00
parent 6afcac84d0
commit 2aef87c9b2
5 changed files with 297 additions and 0 deletions

View File

@ -0,0 +1,35 @@
<?php
namespace Doctrine\Tests\Models\DDC3597;
use Doctrine\Tests\Models\DDC3597\Embeddable\DDC3597Dimension;
/**
* Description of Image
*
* @author Volker von Hoesslin <volker.von.hoesslin@empora.com>
* @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;
}
}

View File

@ -0,0 +1,74 @@
<?php
namespace Doctrine\Tests\Models\DDC3597;
/**
* Description of Media
*
* @author Volker von Hoesslin <volker.von.hoesslin@empora.com>
* @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;
}
}

View File

@ -0,0 +1,78 @@
<?php
namespace Doctrine\Tests\Models\DDC3597;
use Doctrine\ORM\Mapping\DiscriminatorMap;
/**
* Description of Root
*
* @Entity
*
* @InheritanceType("JOINED")
* @DiscriminatorColumn(name="discriminator", type="string")
* @DiscriminatorMap({ "image" = "DDC3597Image"})
* @HasLifecycleCallbacks
*/
abstract class DDC3597Root {
/**
* @var int
*
* @Column(name="id", type="integer", nullable=false)
* @Id
* @GeneratedValue(strategy="IDENTITY")
*/
protected $id;
/**
* @var \DateTime
* @Column(name="created_at", type="datetime", nullable=false)
*/
protected $createdAt = null;
/**
* @var \DateTime
* @Column(name="updated_at", type="datetime", nullable=false)
*/
protected $updatedAt = null;
/**
* Set createdAt
*
* @PrePersist
*/
public function _prePersist() {
$this->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;
}
}

View File

@ -0,0 +1,56 @@
<?php
namespace Doctrine\Tests\Models\DDC3597\Embeddable;
/**
* Description of DDC3597Dimension
*
* @Embeddable
*/
class DDC3597Dimension {
/**
* @var int
* @Column(type="integer", name="width")
*/
private $width;
/**
* @var int
* @Column(type="integer", name="height")
*/
private $height;
function __construct($width = 0, $height = 0) {
$this->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;
}
}

View File

@ -0,0 +1,54 @@
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\Tests\Models\DDC3597\DDC3597Root;
use Doctrine\Tests\Models\DDC3597\DDC3597Media;
use Doctrine\Tests\Models\DDC3597\DDC3597Image;
/**
* @group DDC-117
*/
class DDC3597Test extends \Doctrine\Tests\OrmFunctionalTestCase
{
protected function setUp()
{
parent::setUp();
$this->_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);
}
}