Failed Conditions
Pull Request — master (#2849)
by Luís
63:28
created

TableGeneratorTest::setUp()   A

Complexity

Conditions 4
Paths 18

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 21
rs 9.0534
c 0
b 0
f 0
cc 4
eloc 13
nc 18
nop 0
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) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
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