Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / dbal / tests / Doctrine / Tests / DBAL / Platforms / SqlitePlatformTest.php
1 <?php
2
3 namespace Doctrine\Tests\DBAL\Platforms;
4
5 use Doctrine\DBAL\Platforms\SqlitePlatform;
6 use Doctrine\DBAL\Types\Type;
7
8 require_once __DIR__ . '/../../TestInit.php';
9
10 class SqlitePlatformTest extends AbstractPlatformTestCase
11 {
12     public function createPlatform()
13     {
14         return new SqlitePlatform;
15     }
16
17     public function getGenerateTableSql()
18     {
19         return 'CREATE TABLE test (id INTEGER NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))';
20     }
21
22     public function getGenerateTableWithMultiColumnUniqueIndexSql()
23     {
24         return array(
25             'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL)',
26             'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)',
27         );
28     }
29
30     public function testGeneratesSqlSnippets()
31     {
32         $this->assertEquals('RLIKE', $this->_platform->getRegexpExpression(), 'Regular expression operator is not correct');
33         $this->assertEquals('SUBSTR(column, 5, LENGTH(column))', $this->_platform->getSubstringExpression('column', 5), 'Substring expression without length is not correct');
34         $this->assertEquals('SUBSTR(column, 0, 5)', $this->_platform->getSubstringExpression('column', 0, 5), 'Substring expression with length is not correct');
35     }
36
37     public function testGeneratesTransactionCommands()
38     {
39         $this->assertEquals(
40             'PRAGMA read_uncommitted = 0',
41             $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED)
42         );
43         $this->assertEquals(
44             'PRAGMA read_uncommitted = 1',
45             $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED)
46         );
47         $this->assertEquals(
48             'PRAGMA read_uncommitted = 1',
49             $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ)
50         );
51         $this->assertEquals(
52             'PRAGMA read_uncommitted = 1',
53             $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE)
54         );
55     }
56
57     public function testPrefersIdentityColumns()
58     {
59         $this->assertTrue($this->_platform->prefersIdentityColumns());
60     }
61
62     public function testGeneratesTypeDeclarationForIntegers()
63     {
64         $this->assertEquals(
65             'INTEGER',
66             $this->_platform->getIntegerTypeDeclarationSQL(array())
67         );
68         $this->assertEquals(
69             'INTEGER',
70             $this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true))
71         );
72         $this->assertEquals(
73             'INTEGER',
74             $this->_platform->getIntegerTypeDeclarationSQL(
75                 array('autoincrement' => true, 'primary' => true))
76         );
77     }
78
79     public function testGeneratesTypeDeclarationForStrings()
80     {
81         $this->assertEquals(
82             'CHAR(10)',
83             $this->_platform->getVarcharTypeDeclarationSQL(
84                 array('length' => 10, 'fixed' => true))
85         );
86         $this->assertEquals(
87             'VARCHAR(50)',
88             $this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)),
89             'Variable string declaration is not correct'
90         );
91         $this->assertEquals(
92             'VARCHAR(255)',
93             $this->_platform->getVarcharTypeDeclarationSQL(array()),
94             'Long string declaration is not correct'
95         );
96     }
97
98     public function getGenerateIndexSql()
99     {
100         return 'CREATE INDEX my_idx ON mytable (user_name, last_login)';
101     }
102
103     public function getGenerateUniqueIndexSql()
104     {
105         return 'CREATE UNIQUE INDEX index_name ON test (test, test2)';
106     }
107
108     public function getGenerateForeignKeySql()
109     {
110         $this->markTestSkipped('SQLite does not support ForeignKeys.');
111     }
112
113     public function testModifyLimitQuery()
114     {
115         $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0);
116         $this->assertEquals('SELECT * FROM user LIMIT 10 OFFSET 0', $sql);
117     }
118
119     public function testModifyLimitQueryWithEmptyOffset()
120     {
121         $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10);
122         $this->assertEquals('SELECT * FROM user LIMIT 10', $sql);
123     }
124
125     public function getGenerateAlterTableSql()
126     {
127         $this->markTestSkipped('SQlite does not support ALTER Table.');
128     }
129
130     public function testGetAlterTableSqlDispatchEvent()
131     {
132         $this->markTestSkipped('SQlite does not support ALTER Table.');
133     }
134
135     /**
136      * @group DDC-1845
137      */
138     public function testGenerateTableSqlShouldNotAutoQuotePrimaryKey()
139     {
140         $table = new \Doctrine\DBAL\Schema\Table('test');
141         $table->addColumn('"like"', 'integer', array('notnull' => true, 'autoincrement' => true));
142         $table->setPrimaryKey(array('"like"'));
143
144         $createTableSQL = $this->_platform->getCreateTableSQL($table);
145         $this->assertEquals(
146             'CREATE TABLE test ("like" INTEGER NOT NULL, PRIMARY KEY("like"))',
147             $createTableSQL[0]
148         );
149
150         $this->assertEquals(
151             'ALTER TABLE test ADD PRIMARY KEY ("like")',
152             $this->_platform->getCreatePrimaryKeySQL($table->getIndex('primary'), 'test')
153         );
154     }
155 }