|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
|
|
4
|
|
|
namespace Doctrine\Tests\DBAL\Functional\Schema; |
|
5
|
|
|
|
|
6
|
|
|
use Doctrine\Tests\DbalFunctionalTestCase; |
|
7
|
|
|
|
|
8
|
|
|
class TableTest extends DbalFunctionalTestCase |
|
9
|
|
|
{ |
|
10
|
|
|
public function testColumnsOrder() |
|
11
|
|
|
{ |
|
12
|
|
|
$this->initSchema(); |
|
13
|
|
|
|
|
14
|
|
|
$schema = $this->_conn->getSchemaManager()->createSchema(); |
|
15
|
|
|
|
|
16
|
|
|
$columns = array_keys($schema->getTable('myusers')->getColumns()); |
|
17
|
|
|
|
|
18
|
|
|
$this->assertSame('id', $columns[0]); |
|
19
|
|
|
$this->assertSame('country_id', $columns[1]); |
|
20
|
|
|
$this->assertSame('name', $columns[2]); |
|
21
|
|
|
|
|
22
|
|
|
$this->cleanupSchema(); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
private function getTestSchema() |
|
26
|
|
|
{ |
|
27
|
|
|
$schema = new \Doctrine\DBAL\Schema\Schema(); |
|
28
|
|
|
|
|
29
|
|
|
$countries = $schema->createTable('countries'); |
|
30
|
|
|
$countries->addColumn('id', 'integer'); |
|
31
|
|
|
$countries->setPrimaryKey(array('id')); |
|
32
|
|
|
|
|
33
|
|
|
$users = $schema->createTable('myusers'); |
|
34
|
|
|
$users->addColumn('id', 'integer'); |
|
35
|
|
|
$users->addColumn('name', 'string'); |
|
36
|
|
|
$users->addColumn($this->_conn->quoteIdentifier('country_id'), 'integer'); |
|
37
|
|
|
$users->setPrimaryKey(array('id')); |
|
38
|
|
|
$users->addForeignKeyConstraint($countries, array($this->_conn->quoteIdentifier('country_id')), array('id')); |
|
39
|
|
|
|
|
40
|
|
|
return $schema; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
private function initSchema() |
|
44
|
|
|
{ |
|
45
|
|
|
$queries = $this->getTestSchema()->toSql($this->_conn->getDatabasePlatform()); |
|
46
|
|
|
|
|
47
|
|
|
foreach ($queries as $query) { |
|
48
|
|
|
$this->_conn->exec($query); |
|
49
|
|
|
} |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
private function cleanupSchema() |
|
53
|
|
|
{ |
|
54
|
|
|
$queries = $this->getTestSchema()->toDropSql($this->_conn->getDatabasePlatform()); |
|
55
|
|
|
|
|
56
|
|
|
foreach ($queries as $query) { |
|
57
|
|
|
$this->_conn->exec($query); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|