From 32363a200d805745a9ec30ac0a9d47a9b6b5f7be Mon Sep 17 00:00:00 2001 From: piccoloprincipe Date: Tue, 7 Jul 2009 12:00:22 +0000 Subject: [PATCH] divided some assertions in various cohesive methods and renamed method names to conform to agile documentation (affects #2316) --- .../DBAL/Platforms/MsSqlPlatformTest.php | 87 ++++---- .../DBAL/Platforms/MySqlPlatformTest.php | 185 ++++++++++-------- .../DBAL/Platforms/PostgreSqlPlatformTest.php | 60 ++++-- .../DBAL/Platforms/SqlitePlatformTest.php | 73 ++++--- 4 files changed, 238 insertions(+), 167 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Platforms/MsSqlPlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/MsSqlPlatformTest.php index 77cb5c1af..fb257b2bc 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/MsSqlPlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/MsSqlPlatformTest.php @@ -16,7 +16,7 @@ class MsSqlPlatformTest extends \Doctrine\Tests\DbalTestCase $this->_platform = new MssqlPlatform; } - public function testCreateTableSql() + public function testGeneratesTableCreationSql() { $columns = array( 'id' => array( @@ -40,7 +40,7 @@ class MsSqlPlatformTest extends \Doctrine\Tests\DbalTestCase $this->assertEquals('CREATE TABLE test (id INT AUTO_INCREMENT NOT NULL, test VARCHAR(255) NOT NULL, PRIMARY KEY(id))', $sql[0]); } - public function testAlterTableSql() + public function testGeneratesTableAlterationSql() { $changes = array( 'name' => 'userlist', @@ -57,31 +57,17 @@ class MsSqlPlatformTest extends \Doctrine\Tests\DbalTestCase ); } - public function testCreateIndexSql() + public function testGeneratesSqlSnippets() { - $indexDef = array( - 'fields' => array( - 'user_name' => array( - 'sorting' => 'ASC', - 'length' => 10 - ), - 'last_login' => array() - ) - ); - - $this->assertEquals( - 'CREATE INDEX my_idx ON mytable (user_name, last_login)', - $this->_platform->getCreateIndexSql('mytable', 'my_idx', $indexDef) - ); + $this->assertEquals('RLIKE', $this->_platform->getRegexpExpression(), 'Regular expression operator is not correct'); + $this->assertEquals('`', $this->_platform->getIdentifierQuoteCharacter(), 'Identifier quote character is not correct'); + $this->assertEquals('RAND()', $this->_platform->getRandomExpression(), 'Random function is not correct'); + $this->assertEquals('(column1 + column2 + column3)', $this->_platform->getConcatExpression('column1', 'column2', 'column3'), 'Concatenation expression is not correct'); + $this->assertEquals('CHARACTER SET utf8', $this->_platform->getCharsetFieldDeclaration('utf8'), 'Charset declaration is not correct'); } - public function testSqlSnippets() + public function testGeneratesTransactionsCommands() { - $this->assertEquals('RLIKE', $this->_platform->getRegexpExpression()); - $this->assertEquals('`', $this->_platform->getIdentifierQuoteCharacter()); - $this->assertEquals('RAND()', $this->_platform->getRandomExpression()); - $this->assertEquals('(column1 + column2 + column3)', $this->_platform->getConcatExpression('column1', 'column2', 'column3')); - $this->assertEquals('CHARACTER SET utf8', $this->_platform->getCharsetFieldDeclaration('utf8')); $this->assertEquals( 'SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED', $this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED) @@ -100,7 +86,7 @@ class MsSqlPlatformTest extends \Doctrine\Tests\DbalTestCase ); } - public function testDDLSnippets() + public function testGeneratesDDLSnippets() { $this->assertEquals('SHOW DATABASES', $this->_platform->getShowDatabasesSql()); $this->assertEquals('CREATE DATABASE foobar', $this->_platform->getCreateDatabaseSql('foobar')); @@ -108,7 +94,7 @@ class MsSqlPlatformTest extends \Doctrine\Tests\DbalTestCase $this->assertEquals('DROP TABLE foobar', $this->_platform->getDropTableSql('foobar')); } - public function testTypeDeclarationSql() + public function testGeneratesTypeDeclarationForIntegers() { $this->assertEquals( 'INT', @@ -123,6 +109,10 @@ class MsSqlPlatformTest extends \Doctrine\Tests\DbalTestCase $this->_platform->getIntegerTypeDeclarationSql( array('autoincrement' => true, 'primary' => true) )); + } + + public function testGeneratesTypeDeclarationsForStrings() + { $this->assertEquals( 'CHAR(10)', $this->_platform->getVarcharTypeDeclarationSql( @@ -130,37 +120,64 @@ class MsSqlPlatformTest extends \Doctrine\Tests\DbalTestCase )); $this->assertEquals( 'VARCHAR(50)', - $this->_platform->getVarcharTypeDeclarationSql(array('length' => 50)) + $this->_platform->getVarcharTypeDeclarationSql(array('length' => 50)), + 'Variable string declaration is not correct' ); $this->assertEquals( 'TEXT', - $this->_platform->getVarcharTypeDeclarationSql(array()) + $this->_platform->getVarcharTypeDeclarationSql(array()), + 'Long string declaration is not correct' ); } - public function testPreferences() + public function testPrefersIdentityColumns() { $this->assertTrue($this->_platform->prefersIdentityColumns()); - $this->assertTrue($this->_platform->supportsIdentityColumns()); - $this->assertFalse($this->_platform->supportsSavepoints()); - } - public function testGetCreateConstraintSql() + public function testSupportsIdentityColumns() + { + $this->assertTrue($this->_platform->supportsIdentityColumns()); + } + + public function testDoesNotSupportSavePoints() + { + $this->assertFalse($this->_platform->supportsSavepoints()); + } + + public function testGeneratesConstraintCreationSql() { $sql = $this->_platform->getCreateConstraintSql('test', 'constraint_name', array('fields' => array('test' => array()))); $this->assertEquals($sql, 'ALTER TABLE test ADD CONSTRAINT constraint_name (test)'); } - public function testGetCreateIndexSql() + public function testGeneratesIndexCreationSql() + { + $indexDef = array( + 'fields' => array( + 'user_name' => array( + 'sorting' => 'ASC', + 'length' => 10 + ), + 'last_login' => array() + ) + ); + + $this->assertEquals( + 'CREATE INDEX my_idx ON mytable (user_name, last_login)', + $this->_platform->getCreateIndexSql('mytable', 'my_idx', $indexDef) + ); + } + + public function testGeneratesUniqueIndexCreationSql() { $sql = $this->_platform->getCreateIndexSql('test', 'index_name', array('type' => 'unique', 'fields' => array('test', 'test2'))); $this->assertEquals($sql, 'CREATE UNIQUE INDEX index_name ON test (test, test2)'); } - public function testGetCreateForeignKeySql() + public function testGeneratesForeignKeyCreationSql() { $sql = $this->_platform->getCreateForeignKeySql('test', array('foreignTable' => 'other_table', 'local' => 'fk_name_id', 'foreign' => 'id')); $this->assertEquals($sql, 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table(id)'); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php index d752298fc..b9c6ac822 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php @@ -16,7 +16,7 @@ class MySqlPlatformTest extends \Doctrine\Tests\DbalTestCase $this->_platform = new MySqlPlatform; } - public function testCreateTableSql() + public function testGeneratesTableCreationSql() { $columns = array( 'id' => array( @@ -40,7 +40,7 @@ class MySqlPlatformTest extends \Doctrine\Tests\DbalTestCase $this->assertEquals('CREATE TABLE test (id INT AUTO_INCREMENT NOT NULL, test VARCHAR(255) NOT NULL, PRIMARY KEY(id))', $sql[0]); } - public function testAlterTableSql() + public function testGeneratesTableAlterationSql() { $changes = array( 'name' => 'userlist', @@ -57,7 +57,103 @@ class MySqlPlatformTest extends \Doctrine\Tests\DbalTestCase ); } - public function testCreateIndexSql() + public function testGeneratesSqlSnippets() + { + $this->assertEquals('RLIKE', $this->_platform->getRegexpExpression(), 'Regular expression operator is not correct'); + $this->assertEquals('`', $this->_platform->getIdentifierQuoteCharacter(), 'Quote character is not correct'); + $this->assertEquals('RAND()', $this->_platform->getRandomExpression(), 'Random function is not correct'); + $this->assertEquals('CONCAT(column1, column2, column3)', $this->_platform->getConcatExpression('column1', 'column2', 'column3'), 'Concatenation function is not correct'); + $this->assertEquals('CHARACTER SET utf8', $this->_platform->getCharsetFieldDeclaration('utf8'), 'Charset declaration is not correct'); + } + + public function testGeneratesTransactionsCommands() + { + $this->assertEquals( + 'SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED', + $this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED), + '' + ); + $this->assertEquals( + 'SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED', + $this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED) + ); + $this->assertEquals( + 'SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ', + $this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ) + ); + $this->assertEquals( + 'SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE', + $this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE) + ); + } + + + public function testGeneratesDDLSnippets() + { + $this->assertEquals('SHOW DATABASES', $this->_platform->getShowDatabasesSql()); + $this->assertEquals('CREATE DATABASE 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 testGeneratesTypeDeclarationForIntegers() + { + $this->assertEquals( + 'INT', + $this->_platform->getIntegerTypeDeclarationSql(array()) + ); + $this->assertEquals( + 'INT AUTO_INCREMENT', + $this->_platform->getIntegerTypeDeclarationSql(array('autoincrement' => true) + )); + $this->assertEquals( + 'INT AUTO_INCREMENT', + $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( + 'TEXT', + $this->_platform->getVarcharTypeDeclarationSql(array()), + 'Long string declaration is not correct' + ); + } + + public function testPrefersIdentityColumns() + { + $this->assertTrue($this->_platform->prefersIdentityColumns()); + } + + public function testSupportsIdentityColumns() + { + $this->assertTrue($this->_platform->supportsIdentityColumns()); + } + + public function testDoesNotSupportSavePoints() + { + $this->assertFalse($this->_platform->supportsSavepoints()); + } + + public function testGeneratesConstraintCreationSql() + { + $sql = $this->_platform->getCreateConstraintSql('test', 'constraint_name', array('fields' => array('test' => array()))); + $this->assertEquals($sql, 'ALTER TABLE test ADD CONSTRAINT constraint_name (test)'); + } + + public function testGeneratesIndexCreationSql() { $indexDef = array( 'fields' => array( @@ -75,92 +171,15 @@ class MySqlPlatformTest extends \Doctrine\Tests\DbalTestCase ); } - public function testSqlSnippets() - { - $this->assertEquals('RLIKE', $this->_platform->getRegexpExpression()); - $this->assertEquals('`', $this->_platform->getIdentifierQuoteCharacter()); - $this->assertEquals('RAND()', $this->_platform->getRandomExpression()); - $this->assertEquals('CONCAT(column1, column2, column3)', $this->_platform->getConcatExpression('column1', 'column2', 'column3')); - $this->assertEquals('CHARACTER SET utf8', $this->_platform->getCharsetFieldDeclaration('utf8')); - $this->assertEquals( - 'SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED', - $this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED) - ); - $this->assertEquals( - 'SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED', - $this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED) - ); - $this->assertEquals( - 'SET SESSION TRANSACTION ISOLATION LEVEL REPEATABLE READ', - $this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ) - ); - $this->assertEquals( - 'SET SESSION TRANSACTION ISOLATION LEVEL SERIALIZABLE', - $this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE) - ); - } - - public function testDDLSnippets() - { - $this->assertEquals('SHOW DATABASES', $this->_platform->getShowDatabasesSql()); - $this->assertEquals('CREATE DATABASE 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 testTypeDeclarationSql() - { - $this->assertEquals( - 'INT', - $this->_platform->getIntegerTypeDeclarationSql(array()) - ); - $this->assertEquals( - 'INT AUTO_INCREMENT', - $this->_platform->getIntegerTypeDeclarationSql(array('autoincrement' => true) - )); - $this->assertEquals( - 'INT AUTO_INCREMENT', - $this->_platform->getIntegerTypeDeclarationSql( - array('autoincrement' => true, 'primary' => true) - )); - $this->assertEquals( - 'CHAR(10)', - $this->_platform->getVarcharTypeDeclarationSql( - array('length' => 10, 'fixed' => true) - )); - $this->assertEquals( - 'VARCHAR(50)', - $this->_platform->getVarcharTypeDeclarationSql(array('length' => 50)) - ); - $this->assertEquals( - 'TEXT', - $this->_platform->getVarcharTypeDeclarationSql(array()) - ); - } - - public function testPreferences() - { - $this->assertTrue($this->_platform->prefersIdentityColumns()); - $this->assertTrue($this->_platform->supportsIdentityColumns()); - $this->assertFalse($this->_platform->supportsSavepoints()); - - } - - public function testGetCreateConstraintSql() - { - $sql = $this->_platform->getCreateConstraintSql('test', 'constraint_name', array('fields' => array('test' => array()))); - $this->assertEquals($sql, 'ALTER TABLE test ADD CONSTRAINT constraint_name (test)'); - } - - public function testGetCreateIndexSql() + public function testGeneratesUniqueIndexCreationSql() { $sql = $this->_platform->getCreateIndexSql('test', 'index_name', array('type' => 'unique', 'fields' => array('test', 'test2'))); $this->assertEquals($sql, 'CREATE UNIQUE INDEX index_name ON test (test, test2)'); } - public function testGetCreateForeignKeySql() + public function testGeneratesForeignKeyCreationSql() { $sql = $this->_platform->getCreateForeignKeySql('test', array('foreignTable' => 'other_table', 'local' => 'fk_name_id', 'foreign' => 'id')); $this->assertEquals($sql, 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table(id)'); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php index de29305ae..526485a6b 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php @@ -17,7 +17,7 @@ class PostgreSqlPlatformTest extends \Doctrine\Tests\DbalTestCase $this->_platform = new PostgreSqlPlatform; } - public function testCreateTableSql() + public function testGeneratesTableCreationSql() { $columns = array( 'id' => array( @@ -41,7 +41,7 @@ class PostgreSqlPlatformTest extends \Doctrine\Tests\DbalTestCase } - public function testAlterTableSql() + public function testGeneratesTableAlterationSqlForAddingAndRenaming() { $changes = array( 'name' => 'userlist', @@ -63,7 +63,7 @@ class PostgreSqlPlatformTest extends \Doctrine\Tests\DbalTestCase ); } - public function testCreateIndexSql() + public function testGeneratesIndexCreationSql() { $indexDef = array( 'fields' => array( @@ -80,12 +80,16 @@ class PostgreSqlPlatformTest extends \Doctrine\Tests\DbalTestCase ); } - public function testSqlSnippets() + public function testGeneratesSqlSnippets() + { + $this->assertEquals('SIMILAR TO', $this->_platform->getRegexpExpression(), 'Regular expression operator is not correct'); + $this->assertEquals('"', $this->_platform->getIdentifierQuoteCharacter(), 'Identifier quote character is not correct'); + $this->assertEquals('RANDOM()', $this->_platform->getRandomExpression(), 'Random function is not correct'); + $this->assertEquals('column1 || column2 || column3', $this->_platform->getConcatExpression('column1', 'column2', 'column3'), 'Concatenation expression is not correct'); + } + + public function testGeneratesTransactionCommands() { - $this->assertEquals('SIMILAR TO', $this->_platform->getRegexpExpression()); - $this->assertEquals('"', $this->_platform->getIdentifierQuoteCharacter()); - $this->assertEquals('RANDOM()', $this->_platform->getRandomExpression()); - $this->assertEquals('column1 || column2 || column3', $this->_platform->getConcatExpression('column1', 'column2', 'column3')); $this->assertEquals( 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ UNCOMMITTED', $this->_platform->getSetTransactionIsolationSql(Connection::TRANSACTION_READ_UNCOMMITTED) @@ -104,14 +108,14 @@ class PostgreSqlPlatformTest extends \Doctrine\Tests\DbalTestCase ); } - public function testDDLSnippets() + public function testGeneratesDDLSnippets() { $this->assertEquals('CREATE DATABASE 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 testTypeDeclarationSql() + public function testGeneratesTypeDeclarationForIntegers() { $this->assertEquals( 'INT', @@ -126,22 +130,28 @@ class PostgreSqlPlatformTest extends \Doctrine\Tests\DbalTestCase $this->_platform->getIntegerTypeDeclarationSql( array('autoincrement' => true, 'primary' => true) )); + } + + public function testGeneratesTypeDeclarationForStrings() + { $this->assertEquals( 'CHAR(10)', $this->_platform->getVarcharTypeDeclarationSql( - array('length' => 10, 'fixed' => true) - )); + array('length' => 10, 'fixed' => true)) + ); $this->assertEquals( 'VARCHAR(50)', - $this->_platform->getVarcharTypeDeclarationSql(array('length' => 50)) + $this->_platform->getVarcharTypeDeclarationSql(array('length' => 50)), + 'Variable string declaration is not correct' ); $this->assertEquals( 'TEXT', - $this->_platform->getVarcharTypeDeclarationSql(array()) + $this->_platform->getVarcharTypeDeclarationSql(array()), + 'Long string declaration is not correct' ); } - public function testSequenceSQL() + public function testGeneratesSequenceSqlCommands() { $this->assertEquals( 'CREATE SEQUENCE myseq INCREMENT BY 20 START 1', @@ -157,12 +167,28 @@ class PostgreSqlPlatformTest extends \Doctrine\Tests\DbalTestCase ); } - public function testPreferences() + 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()); } -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php index 9d794869f..c4aad2b77 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php @@ -16,7 +16,7 @@ class SqlitePlatformTest extends \Doctrine\Tests\DbalTestCase $this->_platform = new SqlitePlatform; } - public function testGetCreateTableSql() + public function testGeneratesTableCreationSql() { $columns = array( 'id' => array( @@ -37,41 +37,27 @@ class SqlitePlatformTest extends \Doctrine\Tests\DbalTestCase $this->assertEquals('CREATE TABLE test (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, test VARCHAR(255) DEFAULT NULL)', $sql[0]); } - public function testGetCreateConstraintSql() + public function testGeneratesSqlSnippets() { - $sql = $this->_platform->getCreateConstraintSql('test', 'constraint_name', array('fields' => array('test' => array()))); - $this->assertEquals('ALTER TABLE test ADD CONSTRAINT constraint_name (test)', $sql); + $this->assertEquals('RLIKE', $this->_platform->getRegexpExpression(), 'Regular expression operator is not correct'); + $this->assertEquals('SUBSTR(column, 5, LENGTH(column))', $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 testGetCreateIndexSql() + public function testGeneratesTransactionCommands() { - $sql = $this->_platform->getCreateIndexSql('test', 'index_name', array('type' => 'unique', 'fields' => array('test', 'test2'))); - $this->assertEquals('CREATE UNIQUE INDEX index_name ON test (test, test2)', $sql); - } - - public function testGetCreateForeignKeySql() - { - $sql = $this->_platform->getCreateForeignKeySql('test', array('foreignTable' => 'other_table', 'local' => 'fk_name_id', 'foreign' => 'id')); - $this->assertEquals('ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table(id)', $sql); - } - - public function testExpressionsSql() - { - $this->assertEquals('RLIKE', $this->_platform->getRegexpExpression()); - $this->assertEquals('SUBSTR(column, 5, LENGTH(column))', $this->_platform->getSubstringExpression('column', 5)); - $this->assertEquals('SUBSTR(column, 0, 5)', $this->_platform->getSubstringExpression('column', 0, 5)); $this->assertEquals('PRAGMA read_uncommitted = 0', $this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED)); $this->assertEquals('PRAGMA read_uncommitted = 1', $this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED)); $this->assertEquals('PRAGMA read_uncommitted = 1', $this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ)); $this->assertEquals('PRAGMA read_uncommitted = 1', $this->_platform->getSetTransactionIsolationSql(\Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE)); } - public function testPreferences() + public function testPrefersIdentityColumns() { $this->assertTrue($this->_platform->prefersIdentityColumns()); } - public function testTypeDeclarationSql() + public function testGeneratesTypeDeclarationForIntegers() { $this->assertEquals( 'INTEGER', @@ -79,26 +65,49 @@ class SqlitePlatformTest extends \Doctrine\Tests\DbalTestCase ); $this->assertEquals( 'INTEGER AUTOINCREMENT', - $this->_platform->getIntegerTypeDeclarationSql(array('autoincrement' => true) - )); + $this->_platform->getIntegerTypeDeclarationSql(array('autoincrement' => true)) + ); $this->assertEquals( 'INTEGER PRIMARY KEY AUTOINCREMENT', $this->_platform->getIntegerTypeDeclarationSql( - array('autoincrement' => true, 'primary' => true) - )); + array('autoincrement' => true, 'primary' => true)) + ); + } + + public function testGeneratesTypeDeclarationForStrings() + { $this->assertEquals( 'CHAR(10)', $this->_platform->getVarcharTypeDeclarationSql( - array('length' => 10, 'fixed' => true) - )); + array('length' => 10, 'fixed' => true)) + ); $this->assertEquals( 'VARCHAR(50)', - $this->_platform->getVarcharTypeDeclarationSql(array('length' => 50)) + $this->_platform->getVarcharTypeDeclarationSql(array('length' => 50)), + 'Variable string declaration is not correct' ); $this->assertEquals( 'TEXT', - $this->_platform->getVarcharTypeDeclarationSql(array()) + $this->_platform->getVarcharTypeDeclarationSql(array()), + 'Long string declaration is not correct' ); } - -} \ No newline at end of file + + public function testGeneratesConstraintCreationSql() + { + $sql = $this->_platform->getCreateConstraintSql('test', 'constraint_name', array('fields' => array('test' => array()))); + $this->assertEquals('ALTER TABLE test ADD CONSTRAINT constraint_name (test)', $sql); + } + + public function testGeneratesIndexCreationSql() + { + $sql = $this->_platform->getCreateIndexSql('test', 'index_name', array('type' => 'unique', 'fields' => array('test', 'test2'))); + $this->assertEquals('CREATE UNIQUE INDEX index_name ON test (test, test2)', $sql); + } + + public function testGeneratesForeignKeyCreationSql() + { + $sql = $this->_platform->getCreateForeignKeySql('test', array('foreignTable' => 'other_table', 'local' => 'fk_name_id', 'foreign' => 'id')); + $this->assertEquals('ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table(id)', $sql); + } +}