|
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
|
|
|
} catch (\Exception $e) { |
|
|
|
|
|
|
32
|
|
|
} |
|
33
|
|
|
$this->generator = new TableGenerator($this->_conn); |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
public function testNextVal() |
|
37
|
|
|
{ |
|
38
|
|
|
$id1 = $this->generator->nextValue("tbl1"); |
|
39
|
|
|
$id2 = $this->generator->nextValue("tbl1"); |
|
40
|
|
|
$id3 = $this->generator->nextValue("tbl2"); |
|
41
|
|
|
|
|
42
|
|
|
self::assertTrue($id1 > 0, "First id has to be larger than 0"); |
|
43
|
|
|
self::assertEquals($id1 + 1, $id2, "Second id is one larger than first one."); |
|
44
|
|
|
self::assertEquals($id1, $id3, "First ids from different tables are equal."); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
public function testNextValNotAffectedByOuterTransactions() |
|
48
|
|
|
{ |
|
49
|
|
|
$this->_conn->beginTransaction(); |
|
50
|
|
|
$id1 = $this->generator->nextValue("tbl1"); |
|
51
|
|
|
$this->_conn->rollBack(); |
|
52
|
|
|
$id2 = $this->generator->nextValue("tbl1"); |
|
53
|
|
|
|
|
54
|
|
|
self::assertTrue($id1 > 0, "First id has to be larger than 0"); |
|
55
|
|
|
self::assertEquals($id1 + 1, $id2, "Second id is one larger than first one."); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|