Commit 4191e9f6 authored by Benjamin Eberlei's avatar Benjamin Eberlei

DBAL-374 - Initial testcases

parent 292d5edd
......@@ -4,6 +4,7 @@ namespace Doctrine\Tests\DBAL\Platforms;
use Doctrine\Common\EventManager;
use Doctrine\DBAL\Events;
use Doctrine\DBAL\Schema\Table;
abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
{
......@@ -75,7 +76,7 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
public function testCreateWithNoColumns()
{
$table = new \Doctrine\DBAL\Schema\Table('test');
$table = new Table('test');
$this->setExpectedException('Doctrine\DBAL\DBALException');
$sql = $this->_platform->getCreateTableSQL($table);
......@@ -83,7 +84,7 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
public function testGeneratesTableCreationSql()
{
$table = new \Doctrine\DBAL\Schema\Table('test');
$table = new Table('test');
$table->addColumn('id', 'integer', array('notnull' => true, 'autoincrement' => true));
$table->addColumn('test', 'string', array('notnull' => false, 'length' => 255));
$table->setPrimaryKey(array('id'));
......@@ -96,7 +97,7 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
public function testGenerateTableWithMultiColumnUniqueIndex()
{
$table = new \Doctrine\DBAL\Schema\Table('test');
$table = new Table('test');
$table->addColumn('foo', 'string', array('notnull' => false, 'length' => 255));
$table->addColumn('bar', 'string', array('notnull' => false, 'length' => 255));
$table->addUniqueIndex(array("foo", "bar"));
......@@ -203,7 +204,7 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
{
$expectedSql = $this->getGenerateAlterTableSql();
$tableDiff = new \Doctrine\DBAL\Schema\TableDiff('mytable');
$tableDiff = new TableDiff('mytable');
$tableDiff->newName = 'userlist';
$tableDiff->addedColumns['quota'] = new \Doctrine\DBAL\Schema\Column('quota', \Doctrine\DBAL\Types\Type::getType('integer'), array('notnull' => false));
$tableDiff->removedColumns['foo'] = new \Doctrine\DBAL\Schema\Column('foo', \Doctrine\DBAL\Types\Type::getType('integer'));
......@@ -246,7 +247,7 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$this->_platform->setEventManager($eventManager);
$table = new \Doctrine\DBAL\Schema\Table('test');
$table = new Table('test');
$table->addColumn('foo', 'string', array('notnull' => false, 'length' => 255));
$table->addColumn('bar', 'string', array('notnull' => false, 'length' => 255));
......@@ -307,7 +308,7 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$this->_platform->setEventManager($eventManager);
$tableDiff = new \Doctrine\DBAL\Schema\TableDiff('mytable');
$tableDiff = new TableDiff('mytable');
$tableDiff->addedColumns['added'] = new \Doctrine\DBAL\Schema\Column('added', \Doctrine\DBAL\Types\Type::getType('integer'), array());
$tableDiff->removedColumns['removed'] = new \Doctrine\DBAL\Schema\Column('removed', \Doctrine\DBAL\Types\Type::getType('integer'), array());
$tableDiff->changedColumns['changed'] = new \Doctrine\DBAL\Schema\ColumnDiff(
......@@ -326,7 +327,7 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
*/
public function testCreateTableColumnComments()
{
$table = new \Doctrine\DBAL\Schema\Table('test');
$table = new Table('test');
$table->addColumn('id', 'integer', array('comment' => 'This is a comment'));
$table->setPrimaryKey(array('id'));
......@@ -338,7 +339,7 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
*/
public function testAlterTableColumnComments()
{
$tableDiff = new \Doctrine\DBAL\Schema\TableDiff('mytable');
$tableDiff = new TableDiff('mytable');
$tableDiff->addedColumns['quota'] = new \Doctrine\DBAL\Schema\Column('quota', \Doctrine\DBAL\Types\Type::getType('integer'), array('comment' => 'A comment'));
$tableDiff->changedColumns['bar'] = new \Doctrine\DBAL\Schema\ColumnDiff(
'bar', new \Doctrine\DBAL\Schema\Column(
......@@ -352,7 +353,7 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
public function testCreateTableColumnTypeComments()
{
$table = new \Doctrine\DBAL\Schema\Table('test');
$table = new Table('test');
$table->addColumn('id', 'integer');
$table->addColumn('data', 'array');
$table->setPrimaryKey(array('id'));
......@@ -385,4 +386,33 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$this->assertTrue($keywordList->isKeyword('table'));
}
/**
* @group DBAL-374
*/
public function testQuotedColumnInPrimaryKeyPropagation()
{
$table = new Table('`quoted`');
$table->addColumn('`key`', 'string');
$table->setPrimaryKey(array('key'));
$sql = $this->_platform->getCreateTableSQL($table);
$this->assertEquals($this->getQuotedColumnInPrimaryKeySQL(), $sql);
}
abstract protected function getQuotedColumnInPrimaryKeySQL();
abstract protected function getQuotedColumnInIndexSQL();
/**
* @group DBAL-374
*/
public function testQuotedColumnInIndexPropagation()
{
$table = new Table('`quoted`');
$table->addColumn('`key`', 'string');
$table->addIndex(array('key'));
$sql = $this->_platform->getCreateTableSQL($table);
$this->assertEquals($this->getQuotedColumnInIndexSQL(), $sql);
}
}
......@@ -226,4 +226,18 @@ class MySqlPlatformTest extends AbstractPlatformTestCase
$sql = $this->_platform->getAlterTableSQL($diff);
$this->assertEquals(array("ALTER TABLE test DROP INDEX uniq, ADD INDEX idx (col)"), $sql);
}
protected function getQuotedColumnInPrimaryKeySQL()
{
return array(
'CREATE TABLE `quoted` (`key` VARCHAR(255) NOT NULL, PRIMARY KEY(`key`)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'
);
}
protected function getQuotedColumnInIndexSQL()
{
return array(
'CREATE TABLE `quoted` (`key` VARCHAR(255) NOT NULL, INDEX IDX_22660D028A90ABA9 (`key`)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'
);
}
}
......@@ -269,4 +269,14 @@ class OraclePlatformTest extends AbstractPlatformTestCase
$this->getBitAndComparisonExpressionSql($value1, $value2)
. '+' . $value2 . ')';
}
protected function getQuotedColumnInPrimaryKeySQL()
{
return array();
}
protected function getQuotedColumnInIndexSQL()
{
return array();
}
}
......@@ -225,4 +225,14 @@ class PostgreSqlPlatformTest extends AbstractPlatformTestCase
"COMMENT ON COLUMN test.data IS '(DC2Type:array)'"
);
}
protected function getQuotedColumnInPrimaryKeySQL()
{
return array();
}
protected function getQuotedColumnInIndexSQL()
{
return array();
}
}
......@@ -227,4 +227,14 @@ class SQLServerPlatformTest extends AbstractPlatformTestCase
$idx = new \Doctrine\DBAL\Schema\Index('idx', array('id'), false, true);
$this->assertEquals('ALTER TABLE tbl ADD PRIMARY KEY (id)', $this->_platform->getCreateIndexSQL($idx, 'tbl'));
}
protected function getQuotedColumnInPrimaryKeySQL()
{
return array();
}
protected function getQuotedColumnInIndexSQL()
{
return array();
}
}
......@@ -152,4 +152,14 @@ class SqlitePlatformTest extends AbstractPlatformTestCase
$this->_platform->getCreatePrimaryKeySQL($table->getIndex('primary'), 'test')
);
}
protected function getQuotedColumnInPrimaryKeySQL()
{
return array();
}
protected function getQuotedColumnInIndexSQL()
{
return array();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment