'CASCADE') ); $this->assertEquals( "CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table (id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE", $this->_platform->getForeignKeyDeclarationSQL($foreignKey) ); } 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('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 testGeneratesTransactionCommands() { $this->assertEquals( 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ UNCOMMITTED', $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED) ); $this->assertEquals( 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL READ COMMITTED', $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED) ); $this->assertEquals( 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL REPEATABLE READ', $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ) ); $this->assertEquals( 'SET SESSION CHARACTERISTICS AS TRANSACTION ISOLATION LEVEL SERIALIZABLE', $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE) ); } 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 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 INCREMENT BY 20 MINVALUE 1 START 1', $this->_platform->getCreateSequenceSQL($sequence) ); $this->assertEquals( 'DROP SEQUENCE myseq', $this->_platform->getDropSequenceSQL('myseq') ); $this->assertEquals( "SELECT NEXTVAL('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 getCreateTableColumnCommentsSQL() { return array( "CREATE TABLE test (id INT NOT NULL, PRIMARY KEY(id))", "COMMENT ON COLUMN test.id IS 'This is a comment'", ); } public function getAlterTableColumnCommentsSQL() { return array( "ALTER TABLE mytable ADD quota INT NOT NULL", "COMMENT ON COLUMN mytable.quota IS 'A comment'", "COMMENT ON COLUMN mytable.baz IS 'B comment'", ); } public function getCreateTableColumnTypeCommentsSQL() { return array( "CREATE TABLE test (id INT NOT NULL, data TEXT NOT NULL, PRIMARY KEY(id))", "COMMENT ON COLUMN test.data IS '(DC2Type:array)'" ); } }