Permalink
Browse files

Add tests for AkibanServerPlatform class.

  • Loading branch information...
1 parent 8931cf1 commit 390d5a969ae96c93756747f25c9ebc500dcadb77 @posulliv committed Aug 23, 2012
@@ -352,10 +352,12 @@ public function getAlterTableSQL(TableDiff $diff)
$sql[] = "ALTER TABLE " . $diff->name . " " . $query;
}
if ($columnDiff->hasChanged('default')) {
- // TODO
+ $query = "ALTER " . $oldColumnName . $this->getDefaultValueDeclarationSQL($column->toArray());
+ $sql[] = "ALTER TABLE " . $diff->name . " " . $query;
}
if ($columnDiff->hasChanged('notnull')) {
- // TODO
+ $query = 'ALTER ' . $oldColumnName . ' ' . ($column->getNotNull() ? 'NOT NULL' : 'NULL');
+ $sql[] = "ALTER TABLE " . $diff->name . " " . $query;
}
if ($columnDiff->hasChanged('autoincrement')) {
// TODO
@@ -0,0 +1,182 @@
+<?php
+
+namespace Doctrine\Tests\DBAL\Platforms;
+
+use Doctrine\DBAL\Platforms\AkibanServerPlatform;
+use Doctrine\DBAL\Types\Type;
+
+require_once __DIR__ . '/../../TestInit.php';
+
+class AkibanSrvPlatformTest extends AbstractPlatformTestCase
+{
+ public function createPlatform()
+ {
+ return new AkibanServerPlatform;
+ }
+
+ public function getGenerateTableSql()
+ {
+ return 'CREATE TABLE test (id SERIAL NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))';
+ }
+
+ public function getGenerateTableWithMultiColumnUniqueIndexSql()
+ {
+ return array(
+ 'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL)',
+ 'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)'
+ );
+ }
+
+ public function getGenerateAlterTableSql()
+ {
+ return array(
+ 'ALTER TABLE mytable ADD quota INT DEFAULT NULL',
+ 'ALTER TABLE mytable DROP foo',
+ 'ALTER TABLE mytable ALTER bar SET DATA TYPE VARCHAR(255)',
+ "ALTER TABLE mytable ALTER bar DEFAULT 'def'",
+ 'ALTER TABLE mytable ALTER bar NOT NULL',
+ 'ALTER TABLE mytable ALTER bloo SET DATA TYPE BOOLEAN',
+ 'ALTER TABLE mytable ALTER bloo NOT NULL',
+ 'ALTER TABLE mytable RENAME TO userlist',
+ );
+ }
+
+ public function getGenerateIndexSql()
+ {
+ return 'CREATE INDEX my_idx ON mytable (user_name, last_login)';
+ }
+
+ public function testGeneratesSqlSnippets()
+ {
+ $this->assertEquals('"', $this->_platform->getIdentifierQuoteCharacter(), 'Identifier quote character is not correct');
+ $this->assertEquals('column1 || column2 || column3', $this->_platform->getConcatExpression('column1', 'column2', 'column3'), 'Concatenation expression is not correct');
+ $this->assertEquals('SUBSTR(column, 5)', $this->_platform->getSubstringExpression('column', 5), 'Substring expression without length is not correct');
+ $this->assertEquals('SUBSTR(column, 0, 5)', $this->_platform->getSubstringExpression('column', 0, 5), 'Substring expression with length is not correct');
+ }
+
+ public function testGeneratesDDLSnippets()
+ {
+ $this->assertEquals('CREATE SCHEMA foobar', $this->_platform->getCreateDatabaseSQL('foobar'));
+ $this->assertEquals('DROP DATABASE foobar', $this->_platform->getDropDatabaseSQL('foobar'));
+ $this->assertEquals('DROP TABLE foobar', $this->_platform->getDropTableSQL('foobar'));
+ }
+
+ public function testGenerateTableWithAutoincrement()
+ {
+ $table = new \Doctrine\DBAL\Schema\Table('autoinc_table');
+ $column = $table->addColumn('id', 'integer');
+ $column->setAutoincrement(true);
+
+ $this->assertEquals(array('CREATE TABLE autoinc_table (id SERIAL NOT NULL)'), $this->_platform->getCreateTableSQL($table));
+ }
+
+ public function testGeneratesTypeDeclarationForIntegers()
+ {
+ $this->assertEquals(
+ 'INT',
+ $this->_platform->getIntegerTypeDeclarationSQL(array())
+ );
+ $this->assertEquals(
+ 'SERIAL',
+ $this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true)
+ ));
+ $this->assertEquals(
+ 'SERIAL',
+ $this->_platform->getIntegerTypeDeclarationSQL(
+ array('autoincrement' => true, 'primary' => true)
+ ));
+ }
+
+ public function testGeneratesTypeDeclarationForStrings()
+ {
+ $this->assertEquals(
+ 'CHAR(10)',
+ $this->_platform->getVarcharTypeDeclarationSQL(
+ array('length' => 10, 'fixed' => true))
+ );
+ $this->assertEquals(
+ 'VARCHAR(50)',
+ $this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)),
+ 'Variable string declaration is not correct'
+ );
+ $this->assertEquals(
+ 'VARCHAR(255)',
+ $this->_platform->getVarcharTypeDeclarationSQL(array()),
+ 'Long string declaration is not correct'
+ );
+ }
+
+ public function getGenerateUniqueIndexSql()
+ {
+ return 'CREATE UNIQUE INDEX index_name ON test (test, test2)';
+ }
+
+ public function testGeneratesSequenceSqlCommands()
+ {
+ $sequence = new \Doctrine\DBAL\Schema\Sequence('myseq', 20, 1);
+ $this->assertEquals(
+ 'CREATE SEQUENCE myseq START WITH 1 INCREMENT BY 20 MINVALUE 1',
+ $this->_platform->getCreateSequenceSQL($sequence)
+ );
+ $this->assertEquals(
+ 'DROP SEQUENCE myseq RESTRICT',
+ $this->_platform->getDropSequenceSQL('myseq')
+ );
+ $this->assertEquals(
+ "SELECT NEXT VALUE FOR 'myseq'",
+ $this->_platform->getSequenceNextValSQL('myseq')
+ );
+ }
+
+ public function testDoesNotPreferIdentityColumns()
+ {
+ $this->assertFalse($this->_platform->prefersIdentityColumns());
+ }
+
+ public function testPrefersSequences()
+ {
+ $this->assertTrue($this->_platform->prefersSequences());
+ }
+
+ public function testSupportsIdentityColumns()
+ {
+ $this->assertTrue($this->_platform->supportsIdentityColumns());
+ }
+
+ public function testSupportsSavePoints()
+ {
+ $this->assertTrue($this->_platform->supportsSavepoints());
+ }
+
+ public function testSupportsSequences()
+ {
+ $this->assertTrue($this->_platform->supportsSequences());
+ }
+
+ public function testModifyLimitQuery()
+ {
+ $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0);
+ $this->assertEquals('SELECT * FROM user LIMIT 10 OFFSET 0', $sql);
+ }
+
+ public function testModifyLimitQueryWithEmptyOffset()
+ {
+ $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10);
+ $this->assertEquals('SELECT * FROM user LIMIT 10', $sql);
+ }
+
+ public function getGenerateForeignKeySql()
+ {
+ return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)';
+ }
+
+ protected function getBitAndComparisonExpressionSql($value1, $value2)
+ {
+ return 'BITAND(' . $value1 . ', ' . $value2 . ')';
+ }
+
+ protected function getBitOrComparisonExpressionSql($value1, $value2)
+ {
+ return 'BITOR(' . $value1 . ', ' . $value2 . ')';
+ }
+}

0 comments on commit 390d5a9

Please sign in to comment.