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
|
<?php
namespace Doctrine\DBAL\Tests\Functional;
use Doctrine\DBAL\Id\TableGenerator;
use Doctrine\DBAL\Id\TableGeneratorSchemaVisitor;
use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\DBAL\Tests\FunctionalTestCase;
class TableGeneratorTest extends FunctionalTestCase
{
private TableGenerator $generator;
protected function setUp(): void
{
$platform = $this->connection->getDatabasePlatform();
if ($platform instanceof SqlitePlatform) {
self::markTestSkipped('TableGenerator does not work with SQLite');
}
$this->dropTableIfExists('sequences');
$schema = new Schema();
$visitor = new TableGeneratorSchemaVisitor();
$schema->visit($visitor);
foreach ($schema->toSql($platform) as $sql) {
$this->connection->executeStatement($sql);
}
$this->generator = new TableGenerator($this->connection);
}
public function testNextVal(): void
{
$id1 = $this->generator->nextValue('tbl1');
$id2 = $this->generator->nextValue('tbl1');
$id3 = $this->generator->nextValue('tbl2');
self::assertGreaterThan(0, $id1, 'First id has to be larger than 0');
self::assertEquals($id1 + 1, $id2, 'Second id is one larger than first one.');
self::assertEquals($id1, $id3, 'First ids from different tables are equal.');
}
public function testNextValNotAffectedByOuterTransactions(): void
{
$this->connection->beginTransaction();
$id1 = $this->generator->nextValue('tbl1');
$this->connection->rollBack();
$id2 = $this->generator->nextValue('tbl1');
self::assertGreaterThan(0, $id1, 'First id has to be larger than 0');
self::assertEquals($id1 + 1, $id2, 'Second id is one larger than first one.');
}
}
|