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