2011-06-15 17:15:46 -04:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
|
|
|
|
2016-05-11 01:55:12 +07:00
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase;
|
2011-06-15 17:15:46 -04:00
|
|
|
|
2016-05-11 01:55:12 +07:00
|
|
|
class DDC1209Test extends OrmFunctionalTestCase
|
2011-06-15 17:15:46 -04:00
|
|
|
{
|
|
|
|
protected function setUp()
|
|
|
|
{
|
|
|
|
parent::setUp();
|
|
|
|
try {
|
2016-12-07 23:33:41 +01:00
|
|
|
$this->_schemaTool->createSchema(
|
|
|
|
[
|
2017-05-31 07:59:04 +02:00
|
|
|
$this->_em->getClassMetadata(DDC1209_1::class),
|
|
|
|
$this->_em->getClassMetadata(DDC1209_2::class),
|
|
|
|
$this->_em->getClassMetadata(DDC1209_3::class)
|
2016-12-07 23:33:41 +01:00
|
|
|
]
|
|
|
|
);
|
2011-06-15 17:15:46 -04:00
|
|
|
} catch(\Exception $e) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group DDC-1209
|
|
|
|
*/
|
|
|
|
public function testIdentifierCanHaveCustomType()
|
|
|
|
{
|
2017-05-31 16:36:31 +02:00
|
|
|
$entity = new DDC1209_3();
|
|
|
|
|
|
|
|
$this->_em->persist($entity);
|
2011-06-15 17:15:46 -04:00
|
|
|
$this->_em->flush();
|
2017-05-31 16:36:31 +02:00
|
|
|
|
|
|
|
self::assertSame($entity, $this->_em->find(DDC1209_3::class, $entity->date));
|
2011-06-15 17:15:46 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group DDC-1209
|
|
|
|
*/
|
|
|
|
public function testCompositeIdentifierCanHaveCustomType()
|
|
|
|
{
|
|
|
|
$future1 = new DDC1209_1();
|
|
|
|
|
2017-05-31 16:36:31 +02:00
|
|
|
$this->_em->persist($future1);
|
2011-06-15 17:15:46 -04:00
|
|
|
$this->_em->flush();
|
|
|
|
|
|
|
|
$future2 = new DDC1209_2($future1);
|
|
|
|
|
2017-05-31 16:36:31 +02:00
|
|
|
$this->_em->persist($future2);
|
2011-06-15 17:15:46 -04:00
|
|
|
$this->_em->flush();
|
2017-05-31 16:36:31 +02:00
|
|
|
|
|
|
|
self::assertSame(
|
|
|
|
$future2,
|
|
|
|
$this->_em->find(
|
|
|
|
DDC1209_2::class,
|
|
|
|
[
|
|
|
|
'future1' => $future1,
|
|
|
|
'starting_datetime' => $future2->starting_datetime,
|
|
|
|
'during_datetime' => $future2->during_datetime,
|
|
|
|
'ending_datetime' => $future2->ending_datetime,
|
|
|
|
]
|
|
|
|
)
|
|
|
|
);
|
2011-06-15 17:15:46 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Entity
|
|
|
|
*/
|
|
|
|
class DDC1209_1
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @Id @GeneratedValue @Column(type="integer")
|
|
|
|
*/
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
public function getId()
|
|
|
|
{
|
|
|
|
return $this->id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Entity
|
|
|
|
*/
|
|
|
|
class DDC1209_2
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @Id
|
|
|
|
* @ManyToOne(targetEntity="DDC1209_1")
|
|
|
|
* @JoinColumn(referencedColumnName="id", nullable=false)
|
|
|
|
*/
|
|
|
|
private $future1;
|
|
|
|
/**
|
|
|
|
* @Id
|
|
|
|
* @Column(type="datetime", nullable=false)
|
|
|
|
*/
|
2017-05-31 16:36:31 +02:00
|
|
|
public $starting_datetime;
|
|
|
|
|
2011-06-15 17:15:46 -04:00
|
|
|
/**
|
|
|
|
* @Id
|
|
|
|
* @Column(type="datetime", nullable=false)
|
|
|
|
*/
|
2017-05-31 16:36:31 +02:00
|
|
|
public $during_datetime;
|
|
|
|
|
2011-06-15 17:15:46 -04:00
|
|
|
/**
|
|
|
|
* @Id
|
|
|
|
* @Column(type="datetime", nullable=false)
|
|
|
|
*/
|
2017-05-31 16:36:31 +02:00
|
|
|
public $ending_datetime;
|
2011-06-15 17:15:46 -04:00
|
|
|
|
|
|
|
public function __construct(DDC1209_1 $future1)
|
|
|
|
{
|
|
|
|
$this->future1 = $future1;
|
2011-06-16 08:55:09 -04:00
|
|
|
$this->starting_datetime = new DateTime2();
|
|
|
|
$this->during_datetime = new DateTime2();
|
|
|
|
$this->ending_datetime = new DateTime2();
|
2011-06-15 17:15:46 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Entity
|
|
|
|
*/
|
|
|
|
class DDC1209_3
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @Id
|
2011-10-29 23:58:09 +02:00
|
|
|
* @Column(type="datetime", name="somedate")
|
2011-06-15 17:15:46 -04:00
|
|
|
*/
|
2017-05-31 16:36:31 +02:00
|
|
|
public $date;
|
2011-06-15 17:15:46 -04:00
|
|
|
|
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->date = new DateTime2();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class DateTime2 extends \DateTime
|
|
|
|
{
|
|
|
|
public function __toString()
|
|
|
|
{
|
2011-06-16 08:55:09 -04:00
|
|
|
return $this->format('Y');
|
2011-06-15 17:15:46 -04:00
|
|
|
}
|
2014-04-07 14:43:25 +02:00
|
|
|
}
|