3 namespace Doctrine\Tests\DBAL\Schema\Visitor;
5 require_once __DIR__ . '/../../../TestInit.php';
7 use Doctrine\DBAL\Schema\Schema;
8 use Doctrine\DBAL\Schema\Table;
9 use Doctrine\DBAL\Types\Type;
11 class SchemaSqlCollectorTest extends \PHPUnit_Framework_TestCase
13 public function testCreateSchema()
15 $platformMock = $this->getMock(
16 'Doctrine\DBAL\Platforms\MySqlPlatform',
17 array('getCreateTableSql', 'getCreateSequenceSql', 'getCreateForeignKeySql')
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")));
29 $schema = $this->createFixtureSchema();
31 $sql = $schema->toSql($platformMock);
33 $this->assertEquals(array("foo", "foo", "bar", "baz"), $sql);
36 public function testDropSchema()
38 $platformMock = $this->getMock(
39 'Doctrine\DBAL\Platforms\MySqlPlatform',
40 array('getDropTableSql', 'getDropSequenceSql', 'getDropForeignKeySql')
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"));
52 $schema = $this->createFixtureSchema();
54 $sql = $schema->toDropSql($platformMock);
56 $this->assertEquals(array("fk", "seq", "tbl", "tbl"), $sql);
62 public function createFixtureSchema()
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"));
70 $schema->createSequence("foo_seq");
72 $tableB = $schema->createTable("bar");
73 $tableB->addColumn("id", 'integer');
74 $tableB->setPrimaryKey(array("id"));
76 $tableA->addForeignKeyConstraint($tableB, array("bar"), array("id"));