2009-05-03 22:07:57 +04:00
< ? php
namespace Doctrine\Tests\DBAL\Platforms ;
use Doctrine\DBAL\Platforms\MySqlPlatform ;
use Doctrine\DBAL\Types\Type ;
require_once __DIR__ . '/../../TestInit.php' ;
2009-12-02 21:52:21 +03:00
class MySqlPlatformTest extends AbstractPlatformTestCase
2009-05-03 22:07:57 +04:00
{
2009-12-02 21:52:21 +03:00
public function createPlatform ()
2009-05-03 22:07:57 +04:00
{
2009-12-02 21:52:21 +03:00
return new MysqlPlatform ;
2009-05-03 22:07:57 +04:00
}
2009-12-04 01:15:07 +03:00
public function testGenerateMixedCaseTableCreate ()
{
$table = new \Doctrine\DBAL\Schema\Table ( " Foo " );
$table -> createColumn ( " Bar " , " integer " );
$sql = $this -> _platform -> getCreateTableSql ( $table );
$this -> assertEquals ( 'CREATE TABLE Foo (Bar INT NOT NULL) ENGINE = InnoDB' , array_shift ( $sql ));
}
2009-12-02 21:52:21 +03:00
public function getGenerateTableSql ()
2009-05-03 22:07:57 +04:00
{
2009-12-02 21:52:21 +03:00
return 'CREATE TABLE test (id INT AUTO_INCREMENT NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id)) ENGINE = InnoDB' ;
2009-05-03 22:07:57 +04:00
}
2009-12-11 02:55:47 +03:00
public function getGenerateTableWithMultiColumnUniqueIndexSql ()
{
return array (
'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL, UNIQUE INDEX test_foo_bar_uniq (foo, bar)) ENGINE = InnoDB'
);
}
2009-12-06 02:06:29 +03:00
public function getGenerateAlterTableSql ()
2009-05-03 22:07:57 +04:00
{
2009-12-06 02:06:29 +03:00
return array (
2009-12-06 15:13:15 +03:00
" ALTER TABLE mytable RENAME TO userlist, ADD quota INT DEFAULT NULL, DROP foo, CHANGE bar baz VARCHAR(255) DEFAULT 'def' NOT NULL "
2009-05-03 22:07:57 +04:00
);
}
2009-07-07 16:00:22 +04:00
public function testGeneratesSqlSnippets ()
2009-05-03 22:07:57 +04:00
{
2009-07-07 16:00:22 +04:00
$this -> assertEquals ( 'RLIKE' , $this -> _platform -> getRegexpExpression (), 'Regular expression operator is not correct' );
$this -> assertEquals ( '`' , $this -> _platform -> getIdentifierQuoteCharacter (), 'Quote character is not correct' );
$this -> assertEquals ( 'CONCAT(column1, column2, column3)' , $this -> _platform -> getConcatExpression ( 'column1' , 'column2' , 'column3' ), 'Concatenation function is not correct' );
2009-05-03 22:07:57 +04:00
}
2009-07-07 16:00:22 +04:00
public function testGeneratesTransactionsCommands ()
2009-05-03 22:07:57 +04:00
{
$this -> assertEquals (
'SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED' ,
2009-07-07 16:00:22 +04:00
$this -> _platform -> getSetTransactionIsolationSql ( \Doctrine\DBAL\Connection :: TRANSACTION_READ_UNCOMMITTED ),
''
2009-05-03 22:07:57 +04:00
);
$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 )
);
}
2009-07-07 16:00:22 +04:00
public function testGeneratesDDLSnippets ()
2009-05-03 22:07:57 +04:00
{
$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' ));
}
2009-07-07 16:00:22 +04:00
public function testGeneratesTypeDeclarationForIntegers ()
2009-05-03 22:07:57 +04:00
{
$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 )
));
2009-07-07 16:00:22 +04:00
}
public function testGeneratesTypeDeclarationForStrings ()
{
2009-05-03 22:07:57 +04:00
$this -> assertEquals (
'CHAR(10)' ,
$this -> _platform -> getVarcharTypeDeclarationSql (
array ( 'length' => 10 , 'fixed' => true )
));
$this -> assertEquals (
'VARCHAR(50)' ,
2009-07-07 16:00:22 +04:00
$this -> _platform -> getVarcharTypeDeclarationSql ( array ( 'length' => 50 )),
'Variable string declaration is not correct'
2009-05-03 22:07:57 +04:00
);
$this -> assertEquals (
2009-08-21 22:13:22 +04:00
'VARCHAR(255)' ,
2009-07-07 16:00:22 +04:00
$this -> _platform -> getVarcharTypeDeclarationSql ( array ()),
'Long string declaration is not correct'
2009-05-03 22:07:57 +04:00
);
}
2009-07-07 16:00:22 +04:00
public function testPrefersIdentityColumns ()
2009-05-03 22:07:57 +04:00
{
$this -> assertTrue ( $this -> _platform -> prefersIdentityColumns ());
2009-07-07 16:00:22 +04:00
}
public function testSupportsIdentityColumns ()
{
2009-05-03 22:07:57 +04:00
$this -> assertTrue ( $this -> _platform -> supportsIdentityColumns ());
}
2009-07-07 16:00:22 +04:00
public function testDoesNotSupportSavePoints ()
{
$this -> assertFalse ( $this -> _platform -> supportsSavepoints ());
}
2009-12-02 21:52:21 +03:00
public function getGenerateIndexSql ()
2009-07-07 16:00:22 +04:00
{
2009-12-02 21:52:21 +03:00
return 'CREATE INDEX my_idx ON mytable (user_name, last_login)' ;
2009-07-07 16:00:22 +04:00
}
2009-12-02 21:52:21 +03:00
public function getGenerateUniqueIndexSql ()
2009-05-03 22:07:57 +04:00
{
2009-12-02 21:52:21 +03:00
return 'CREATE UNIQUE INDEX index_name ON test (test, test2)' ;
2009-05-03 22:07:57 +04:00
}
2009-12-02 21:52:21 +03:00
public function getGenerateForeignKeySql ()
2009-05-03 22:07:57 +04:00
{
2009-12-02 21:52:21 +03:00
return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table(id)' ;
2009-05-03 22:07:57 +04:00
}
2009-07-14 02:59:36 +04:00
public function testModifyLimitQuery ()
{
$sql = $this -> _platform -> modifyLimitQuery ( 'SELECT * FROM user' , 10 , 0 );
2009-10-12 23:10:41 +04:00
$this -> assertEquals ( 'SELECT * FROM user LIMIT 10 OFFSET 0' , $sql );
2009-07-14 02:59:36 +04:00
}
public function testModifyLimitQueryWithEmptyOffset ()
{
$sql = $this -> _platform -> modifyLimitQuery ( 'SELECT * FROM user' , 10 );
$this -> assertEquals ( 'SELECT * FROM user LIMIT 10' , $sql );
}
2009-11-05 21:55:02 +03:00
/**
* @ group DDC - 118
*/
public function testGetDateTimeTypeDeclarationSql ()
{
$this -> assertEquals ( " DATETIME " , $this -> _platform -> getDateTimeTypeDeclarationSql ( array ( 'version' => false )));
$this -> assertEquals ( " TIMESTAMP " , $this -> _platform -> getDateTimeTypeDeclarationSql ( array ( 'version' => true )));
$this -> assertEquals ( " DATETIME " , $this -> _platform -> getDateTimeTypeDeclarationSql ( array ()));
}
2009-07-14 02:59:36 +04:00
}