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
|
<?php
declare(strict_types=1);
namespace Doctrine\Tests\ORM\Functional;
use Doctrine\ORM\Mapping\Column;
use Doctrine\ORM\Mapping\Entity;
use Doctrine\ORM\Mapping\GeneratedValue;
use Doctrine\ORM\Mapping\Id;
use Doctrine\ORM\Mapping\Table;
use Doctrine\Tests\OrmFunctionalTestCase;
class SequenceEmulatedIdentityStrategyTest extends OrmFunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();
if (! $this->_em->getConnection()->getDatabasePlatform()->usesSequenceEmulatedIdentityColumns()) {
self::markTestSkipped(
'This test is special to platforms emulating IDENTITY key generation strategy through sequences.'
);
} else {
$this->createSchemaForModels(SequenceEmulatedIdentityEntity::class);
}
}
protected function tearDown(): void
{
parent::tearDown();
$connection = $this->_em->getConnection();
$platform = $connection->getDatabasePlatform();
// drop sequence manually due to dependency
$connection->executeStatement(
$platform->getDropSequenceSQL(
$platform->getIdentitySequenceName('seq_identity', 'id')
)
);
}
public function testPreSavePostSaveCallbacksAreInvoked(): void
{
$entity = new SequenceEmulatedIdentityEntity();
$entity->setValue('hello');
$this->_em->persist($entity);
$this->_em->flush();
self::assertIsNumeric($entity->getId());
self::assertGreaterThan(0, $entity->getId());
self::assertTrue($this->_em->contains($entity));
}
}
/**
* @Entity
* @Table(name="seq_identity")
*/
class SequenceEmulatedIdentityEntity
{
/**
* @var int
* @Id
* @Column(type="integer")
* @GeneratedValue(strategy="IDENTITY")
*/
private $id;
/**
* @var string
* @Column(type="string", length=255)
*/
private $value;
public function getId(): int
{
return $this->id;
}
public function getValue(): string
{
return $this->value;
}
public function setValue(string $value): void
{
$this->value = $value;
}
}
|