3 namespace Doctrine\Tests\DBAL\Functional;
5 use Doctrine\DBAL\Id\TableGenerator;
10 class TableGeneratorTest extends \Doctrine\Tests\DbalFunctionalTestCase
14 public function setUp()
18 $platform = $this->_conn->getDatabasePlatform();
19 if ($platform->getName() == "sqlite") {
20 $this->markTestSkipped('TableGenerator does not work with SQLite');
24 $schema = new \Doctrine\DBAL\Schema\Schema();
25 $visitor = new \Doctrine\DBAL\Id\TableGeneratorSchemaVisitor();
26 $schema->visit($visitor);
28 foreach ($schema->toSql($platform) as $sql) {
29 $this->_conn->exec($sql);
32 } catch(\Exception $e) {
34 $this->generator = new TableGenerator($this->_conn);
37 public function testNextVal()
39 $id1 = $this->generator->nextValue("tbl1");
40 $id2 = $this->generator->nextValue("tbl1");
41 $id3 = $this->generator->nextValue("tbl2");
43 $this->assertTrue($id1 > 0, "First id has to be larger than 0");
44 $this->assertEquals($id1 + 1, $id2, "Second id is one larger than first one.");
45 $this->assertEquals($id1, $id3, "First ids from different tables are equal.");
48 public function testNextValNotAffectedByOuterTransactions()
50 $this->_conn->beginTransaction();
51 $id1 = $this->generator->nextValue("tbl1");
52 $this->_conn->rollBack();
53 $id2 = $this->generator->nextValue("tbl1");
55 $this->assertTrue($id1 > 0, "First id has to be larger than 0");
56 $this->assertEquals($id1 + 1, $id2, "Second id is one larger than first one.");