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