2013-05-01 20:30:45 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Doctrine\Tests\ORM\Functional\Ticket;
|
|
|
|
|
|
|
|
use Doctrine\DBAL\Types\StringType;
|
|
|
|
use Doctrine\DBAL\Types\Type;
|
|
|
|
use Doctrine\DBAL\Platforms\AbstractPlatform;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group DDC-1998
|
|
|
|
*/
|
|
|
|
class DDC1998Test extends \Doctrine\Tests\OrmFunctionalTestCase
|
|
|
|
{
|
|
|
|
public function testSqlConversionAsIdentifier()
|
|
|
|
{
|
2016-12-08 18:01:04 +01:00
|
|
|
Type::addType('ddc1998', DDC1998Type::class);
|
2013-05-01 20:30:45 +02:00
|
|
|
|
2016-12-07 23:33:41 +01:00
|
|
|
$this->_schemaTool->createSchema(
|
|
|
|
[
|
2016-12-08 18:01:04 +01:00
|
|
|
$this->_em->getClassMetadata(DDC1998Entity::class),
|
2016-12-07 23:33:41 +01:00
|
|
|
]
|
|
|
|
);
|
2013-05-01 20:30:45 +02:00
|
|
|
|
|
|
|
$entity = new DDC1998Entity();
|
|
|
|
$entity->id = new DDC1998Id("foo");
|
|
|
|
|
|
|
|
$this->_em->persist($entity);
|
|
|
|
$this->_em->flush();
|
|
|
|
|
|
|
|
$entity->num++;
|
|
|
|
|
|
|
|
$this->_em->flush();
|
|
|
|
|
|
|
|
$this->_em->remove($entity);
|
|
|
|
$this->_em->flush();
|
|
|
|
$this->_em->clear();
|
|
|
|
|
|
|
|
|
2016-12-08 18:01:04 +01:00
|
|
|
$found = $this->_em->find(DDC1998Entity::class, $entity->id);
|
2013-05-01 20:30:45 +02:00
|
|
|
$this->assertNull($found);
|
|
|
|
|
2016-12-08 18:01:04 +01:00
|
|
|
$found = $this->_em->find(DDC1998Entity::class, "foo");
|
2013-05-01 20:30:45 +02:00
|
|
|
$this->assertNull($found);
|
|
|
|
|
2016-12-08 18:01:04 +01:00
|
|
|
$this->assertEquals(0, count($this->_em->getRepository(DDC1998Entity::class)->findAll()));
|
2013-05-01 20:30:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Entity
|
|
|
|
*/
|
|
|
|
class DDC1998Entity
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @Id @Column(type="ddc1998")
|
|
|
|
*/
|
|
|
|
public $id;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Column(type="integer")
|
|
|
|
*/
|
|
|
|
public $num = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
class DDC1998Type extends StringType
|
|
|
|
{
|
|
|
|
const NAME = 'ddc1998';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function convertToDatabaseValue($value, AbstractPlatform $platform)
|
|
|
|
{
|
|
|
|
return (string)$value;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function convertToPhpValue($value, AbstractPlatform $platform)
|
|
|
|
{
|
|
|
|
return new DDC1998Id($value);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* {@inheritdoc}
|
|
|
|
*/
|
|
|
|
public function getName()
|
|
|
|
{
|
|
|
|
return self::NAME;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class DDC1998Id
|
|
|
|
{
|
|
|
|
private $val;
|
|
|
|
|
|
|
|
public function __construct($val)
|
|
|
|
{
|
|
|
|
$this->val = $val;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __toString()
|
|
|
|
{
|
|
|
|
return $this->val;
|
|
|
|
}
|
|
|
|
}
|