Rajout de doctrine/orm
[zf2.biz/galerie.git] / vendor / doctrine / dbal / tests / Doctrine / Tests / DBAL / Schema / Visitor / SchemaSqlCollectorTest.php
1 <?php
2
3 namespace Doctrine\Tests\DBAL\Schema\Visitor;
4
5 require_once __DIR__ . '/../../../TestInit.php';
6
7 use Doctrine\DBAL\Schema\Schema;
8 use Doctrine\DBAL\Schema\Table;
9 use Doctrine\DBAL\Types\Type;
10
11 class SchemaSqlCollectorTest extends \PHPUnit_Framework_TestCase
12 {
13     public function testCreateSchema()
14     {
15         $platformMock = $this->getMock(
16             'Doctrine\DBAL\Platforms\MySqlPlatform',
17             array('getCreateTableSql', 'getCreateSequenceSql', 'getCreateForeignKeySql')
18         );
19         $platformMock->expects($this->exactly(2))
20                      ->method('getCreateTableSql')
21                      ->will($this->returnValue(array("foo")));
22         $platformMock->expects($this->exactly(1))
23                      ->method('getCreateSequenceSql')
24                      ->will($this->returnValue(array("bar")));
25         $platformMock->expects($this->exactly(1))
26                      ->method('getCreateForeignKeySql')
27                      ->will($this->returnValue(array("baz")));
28
29         $schema = $this->createFixtureSchema();
30
31         $sql = $schema->toSql($platformMock);
32
33         $this->assertEquals(array("foo", "foo", "bar", "baz"), $sql);
34     }
35
36     public function testDropSchema()
37     {
38         $platformMock = $this->getMock(
39             'Doctrine\DBAL\Platforms\MySqlPlatform',
40             array('getDropTableSql', 'getDropSequenceSql', 'getDropForeignKeySql')
41         );
42         $platformMock->expects($this->exactly(2))
43                      ->method('getDropTableSql')
44                      ->will($this->returnValue("tbl"));
45         $platformMock->expects($this->exactly(1))
46                      ->method('getDropSequenceSql')
47                      ->will($this->returnValue("seq"));
48         $platformMock->expects($this->exactly(1))
49                      ->method('getDropForeignKeySql')
50                      ->will($this->returnValue("fk"));
51
52         $schema = $this->createFixtureSchema();
53
54         $sql = $schema->toDropSql($platformMock);
55
56         $this->assertEquals(array("fk", "seq", "tbl", "tbl"), $sql);
57     }
58
59     /**
60      * @return Schema
61      */
62     public function createFixtureSchema()
63     {
64         $schema = new Schema();
65         $tableA = $schema->createTable("foo");
66         $tableA->addColumn("id", 'integer');
67         $tableA->addColumn("bar", 'string', array('length' => 255));
68         $tableA->setPrimaryKey(array("id"));
69
70         $schema->createSequence("foo_seq");
71
72         $tableB = $schema->createTable("bar");
73         $tableB->addColumn("id", 'integer');
74         $tableB->setPrimaryKey(array("id"));
75
76         $tableA->addForeignKeyConstraint($tableB, array("bar"), array("id"));
77
78         return $schema;
79     }
80 }