doctrine /
dbal
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Doctrine\DBAL\Tests\Functional; |
||
| 6 | |||
| 7 | use Doctrine\DBAL\Id\TableGenerator; |
||
| 8 | use Doctrine\DBAL\Id\TableGeneratorSchemaVisitor; |
||
| 9 | use Doctrine\DBAL\Schema\Schema; |
||
| 10 | use Doctrine\DBAL\Tests\FunctionalTestCase; |
||
| 11 | use Throwable; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @group DDC-450 |
||
| 15 | */ |
||
| 16 | class TableGeneratorTest extends FunctionalTestCase |
||
| 17 | { |
||
| 18 | /** @var TableGenerator */ |
||
| 19 | private $generator; |
||
| 20 | |||
| 21 | protected function setUp() : void |
||
| 22 | { |
||
| 23 | parent::setUp(); |
||
| 24 | |||
| 25 | $platform = $this->connection->getDatabasePlatform(); |
||
| 26 | if ($platform->getName() === 'sqlite') { |
||
| 27 | self::markTestSkipped('TableGenerator does not work with SQLite'); |
||
| 28 | } |
||
| 29 | |||
| 30 | try { |
||
| 31 | $schema = new Schema(); |
||
| 32 | $visitor = new TableGeneratorSchemaVisitor(); |
||
| 33 | $schema->visit($visitor); |
||
| 34 | |||
| 35 | foreach ($schema->toSql($platform) as $sql) { |
||
| 36 | $this->connection->exec($sql); |
||
| 37 | } |
||
| 38 | } catch (Throwable $e) { |
||
|
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
Loading history...
|
|||
| 39 | } |
||
| 40 | |||
| 41 | $this->generator = new TableGenerator($this->connection); |
||
| 42 | } |
||
| 43 | |||
| 44 | public function testNextVal() : void |
||
| 45 | { |
||
| 46 | $id1 = $this->generator->nextValue('tbl1'); |
||
| 47 | $id2 = $this->generator->nextValue('tbl1'); |
||
| 48 | $id3 = $this->generator->nextValue('tbl2'); |
||
| 49 | |||
| 50 | self::assertGreaterThan(0, $id1, 'First id has to be larger than 0'); |
||
| 51 | self::assertEquals($id1 + 1, $id2, 'Second id is one larger than first one.'); |
||
| 52 | self::assertEquals($id1, $id3, 'First ids from different tables are equal.'); |
||
| 53 | } |
||
| 54 | |||
| 55 | public function testNextValNotAffectedByOuterTransactions() : void |
||
| 56 | { |
||
| 57 | $this->connection->beginTransaction(); |
||
| 58 | $id1 = $this->generator->nextValue('tbl1'); |
||
| 59 | $this->connection->rollBack(); |
||
| 60 | $id2 = $this->generator->nextValue('tbl1'); |
||
| 61 | |||
| 62 | self::assertGreaterThan(0, $id1, 'First id has to be larger than 0'); |
||
| 63 | self::assertEquals($id1 + 1, $id2, 'Second id is one larger than first one.'); |
||
| 64 | } |
||
| 65 | } |
||
| 66 |