|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
|
4
|
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Platforms\AbstractPlatform; |
|
6
|
|
|
use Doctrine\DBAL\Types as DBALTypes; |
|
7
|
|
|
|
|
8
|
|
|
class DDC5684Test extends \Doctrine\Tests\OrmFunctionalTestCase |
|
9
|
|
|
{ |
|
10
|
|
|
protected function setUp() |
|
11
|
|
|
{ |
|
12
|
|
|
parent::setUp(); |
|
13
|
|
|
|
|
14
|
|
|
if (DBALTypes\Type::hasType(DDC5684ObjectIdType::NAME)) { |
|
15
|
|
|
DBALTypes\Type::overrideType(DDC5684ObjectIdType::NAME, DDC5684ObjectIdType::CLASSNAME); |
|
16
|
|
|
} else { |
|
17
|
|
|
DBALTypes\Type::addType(DDC5684ObjectIdType::NAME, DDC5684ObjectIdType::CLASSNAME); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
$this->_schemaTool->createSchema([$this->_em->getClassMetadata(DDC5684Object::CLASSNAME)]); |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
protected function tearDown() |
|
24
|
|
|
{ |
|
25
|
|
|
$this->_schemaTool->dropSchema([$this->_em->getClassMetadata(DDC5684Object::CLASSNAME)]); |
|
26
|
|
|
|
|
27
|
|
|
parent::tearDown(); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function testAutoIncrementIdWithCustomType() |
|
31
|
|
|
{ |
|
32
|
|
|
$object = new DDC5684Object(); |
|
33
|
|
|
$this->_em->persist($object); |
|
34
|
|
|
$this->_em->flush(); |
|
35
|
|
|
|
|
36
|
|
|
$this->assertInstanceOf(DDC5684ObjectId::CLASSNAME, $object->id); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
public function testFetchObjectWithAutoIncrementedCustomType() |
|
40
|
|
|
{ |
|
41
|
|
|
$object = new DDC5684Object(); |
|
42
|
|
|
$this->_em->persist($object); |
|
43
|
|
|
$this->_em->flush(); |
|
44
|
|
|
$this->_em->clear(); |
|
45
|
|
|
|
|
46
|
|
|
$rawId = $object->id->value; |
|
47
|
|
|
$object = $this->_em->find(DDC5684Object::CLASSNAME, new DDC5684ObjectId($rawId)); |
|
48
|
|
|
|
|
49
|
|
|
$this->assertInstanceOf(DDC5684ObjectId::CLASSNAME, $object->id); |
|
50
|
|
|
$this->assertEquals($rawId, $object->id->value); |
|
51
|
|
|
} |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
class DDC5684ObjectIdType extends DBALTypes\IntegerType |
|
55
|
|
|
{ |
|
56
|
|
|
const NAME = 'ticket_5684_object_id'; |
|
57
|
|
|
const CLASSNAME = __CLASS__; |
|
58
|
|
|
|
|
59
|
|
|
public function convertToPHPValue($value, AbstractPlatform $platform) |
|
60
|
|
|
{ |
|
61
|
|
|
return new DDC5684ObjectId($value); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function convertToDatabaseValue($value, AbstractPlatform $platform) |
|
65
|
|
|
{ |
|
66
|
|
|
return $value->value; |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
public function getName() |
|
70
|
|
|
{ |
|
71
|
|
|
return self::NAME; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
public function requiresSQLCommentHint(AbstractPlatform $platform) |
|
75
|
|
|
{ |
|
76
|
|
|
return true; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
class DDC5684ObjectId |
|
81
|
|
|
{ |
|
82
|
|
|
const CLASSNAME = __CLASS__; |
|
83
|
|
|
|
|
84
|
|
|
public $value; |
|
85
|
|
|
|
|
86
|
|
|
public function __construct($value) |
|
87
|
|
|
{ |
|
88
|
|
|
$this->value = $value; |
|
89
|
|
|
} |
|
90
|
|
|
|
|
91
|
|
|
public function __toString() |
|
92
|
|
|
{ |
|
93
|
|
|
return (string) $this->value; |
|
94
|
|
|
} |
|
95
|
|
|
} |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* @Entity |
|
99
|
|
|
* @Table(name="ticket_5684_objects") |
|
100
|
|
|
*/ |
|
101
|
|
|
class DDC5684Object |
|
102
|
|
|
{ |
|
103
|
|
|
const CLASSNAME = __CLASS__; |
|
104
|
|
|
|
|
105
|
|
|
/** |
|
106
|
|
|
* @Id |
|
107
|
|
|
* @Column(type="ticket_5684_object_id") |
|
108
|
|
|
* @GeneratedValue(strategy="AUTO") |
|
109
|
|
|
*/ |
|
110
|
|
|
public $id; |
|
111
|
|
|
} |
|
112
|
|
|
|