1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket; |
4
|
|
|
|
5
|
|
|
use Doctrine\DBAL\Platforms\AbstractPlatform; |
6
|
|
|
use Doctrine\DBAL\Types\Type; |
7
|
|
|
use Doctrine\ORM\EntityManager; |
8
|
|
|
use Doctrine\ORM\Id\AbstractIdGenerator; |
9
|
|
|
use Doctrine\Tests\OrmFunctionalTestCase; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @group 5804 |
13
|
|
|
*/ |
14
|
|
|
final class GH5804Test extends OrmFunctionalTestCase |
15
|
|
|
{ |
16
|
|
|
protected function setUp() |
17
|
|
|
{ |
18
|
|
|
parent::setUp(); |
19
|
|
|
|
20
|
|
|
Type::addType(GH5804Type::NAME, GH5804Type::class); |
21
|
|
|
|
22
|
|
|
$this->_schemaTool->createSchema( |
23
|
|
|
[$this->_em->getClassMetadata(GH5804Article::class)] |
24
|
|
|
); |
25
|
|
|
} |
26
|
|
|
|
27
|
|
|
public function testTextColumnSaveAndRetrieve2() |
28
|
|
|
{ |
29
|
|
|
$firstArticle = new GH5804Article; |
30
|
|
|
$firstArticle->text = 'Max'; |
31
|
|
|
$this->_em->persist($firstArticle); |
32
|
|
|
$this->_em->flush(); |
33
|
|
|
|
34
|
|
|
self::assertSame(1, $firstArticle->version); |
35
|
|
|
|
36
|
|
|
$firstArticle->text = 'Moritz'; |
37
|
|
|
$this->_em->persist($firstArticle); |
38
|
|
|
$this->_em->flush(); |
39
|
|
|
|
40
|
|
|
self::assertSame(2, $firstArticle->version); |
41
|
|
|
} |
42
|
|
|
} |
43
|
|
|
|
44
|
|
|
final class GH5804Generator extends AbstractIdGenerator |
45
|
|
|
{ |
46
|
|
|
/** |
47
|
|
|
* {@inheritdoc} |
48
|
|
|
*/ |
49
|
|
|
public function generate(EntityManager $em, $entity) |
50
|
|
|
{ |
51
|
|
|
return 'test5804'; |
52
|
|
|
} |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
final class GH5804Type extends Type |
56
|
|
|
{ |
57
|
|
|
const NAME = 'GH5804Type'; |
58
|
|
|
|
59
|
|
|
public function getName() |
60
|
|
|
{ |
61
|
|
|
return self::NAME; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* {@inheritdoc} |
66
|
|
|
*/ |
67
|
|
|
public function getSQLDeclaration(array $fieldDeclaration, AbstractPlatform $platform) |
68
|
|
|
{ |
69
|
|
|
return $platform->getVarcharTypeDeclarationSQL($fieldDeclaration); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* {@inheritdoc} |
74
|
|
|
*/ |
75
|
|
|
public function convertToDatabaseValue($value, AbstractPlatform $platform) |
76
|
|
|
{ |
77
|
|
|
if (empty($value)) { |
78
|
|
|
return null; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
return 'testGh5804DbValue'; |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* @Entity |
87
|
|
|
*/ |
88
|
|
|
class GH5804Article |
89
|
|
|
{ |
90
|
|
|
/** |
91
|
|
|
* @Id |
92
|
|
|
* @Column(type="GH5804Type") |
93
|
|
|
* @GeneratedValue(strategy="CUSTOM") |
94
|
|
|
* @CustomIdGenerator(class=\Doctrine\Tests\ORM\Functional\Ticket\GH5804Generator::class) |
95
|
|
|
*/ |
96
|
|
|
public $id; |
97
|
|
|
|
98
|
|
|
/** |
99
|
|
|
* @Version |
100
|
|
|
* @Column(type="integer") |
101
|
|
|
*/ |
102
|
|
|
public $version; |
103
|
|
|
|
104
|
|
|
/** |
105
|
|
|
* @Column(type="text") |
106
|
|
|
*/ |
107
|
|
|
public $text; |
108
|
|
|
} |
109
|
|
|
|