1
0
mirror of synced 2025-02-03 22:09:26 +03:00

145 lines
2.9 KiB
PHP
Raw Normal View History

2011-06-15 17:15:46 -04:00
<?php
namespace Doctrine\Tests\ORM\Functional\Ticket;
use Doctrine\Tests\OrmFunctionalTestCase;
2011-06-15 17:15:46 -04:00
class DDC1209Test extends OrmFunctionalTestCase
2011-06-15 17:15:46 -04:00
{
protected function setUp()
{
parent::setUp();
try {
$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)
]
);
2011-06-15 17:15:46 -04:00
} catch(\Exception $e) {
}
}
/**
* @group DDC-1209
*/
public function testIdentifierCanHaveCustomType()
{
$entity = new DDC1209_3();
$this->_em->persist($entity);
2011-06-15 17:15:46 -04:00
$this->_em->flush();
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();
$this->_em->persist($future1);
2011-06-15 17:15:46 -04:00
$this->_em->flush();
$future2 = new DDC1209_2($future1);
$this->_em->persist($future2);
2011-06-15 17:15:46 -04:00
$this->_em->flush();
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)
*/
public $starting_datetime;
2011-06-15 17:15:46 -04:00
/**
* @Id
* @Column(type="datetime", nullable=false)
*/
public $during_datetime;
2011-06-15 17:15:46 -04:00
/**
* @Id
* @Column(type="datetime", nullable=false)
*/
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
*/
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
}
}