From ce6aebc8abac2ca67f850b7a97d8c58dfa5acccd Mon Sep 17 00:00:00 2001 From: piccoloprincipe Date: Sat, 11 Jul 2009 08:48:57 +0000 Subject: [PATCH] [2.0] expanded tests for DBAL components --- tests/Doctrine/Tests/DBAL/AllTests.php | 3 +- .../Tests/DBAL/Mocks/MockPlatform.php | 14 +++++++-- .../DBAL/Platforms/PostgreSqlPlatformTest.php | 17 ++++++++++ .../Doctrine/Tests/DBAL/Types/StringTest.php | 31 +++++++++++++++++++ 4 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 tests/Doctrine/Tests/DBAL/Types/StringTest.php diff --git a/tests/Doctrine/Tests/DBAL/AllTests.php b/tests/Doctrine/Tests/DBAL/AllTests.php index e1b5372cc..6291a771d 100644 --- a/tests/Doctrine/Tests/DBAL/AllTests.php +++ b/tests/Doctrine/Tests/DBAL/AllTests.php @@ -39,6 +39,7 @@ class AllTests $suite->addTestSuite('Doctrine\Tests\DBAL\Types\DecimalTest'); $suite->addTestSuite('Doctrine\Tests\DBAL\Types\IntegerTest'); $suite->addTestSuite('Doctrine\Tests\DBAL\Types\SmallIntTest'); + $suite->addTestSuite('Doctrine\Tests\DBAL\Types\StringTest'); $suite->addTest(Functional\AllTests::suite()); @@ -48,4 +49,4 @@ class AllTests if (PHPUnit_MAIN_METHOD == 'Dbal_Platforms_AllTests::main') { AllTests::main(); -} \ No newline at end of file +} diff --git a/tests/Doctrine/Tests/DBAL/Mocks/MockPlatform.php b/tests/Doctrine/Tests/DBAL/Mocks/MockPlatform.php index 388dc2ba0..c354f8fc2 100644 --- a/tests/Doctrine/Tests/DBAL/Mocks/MockPlatform.php +++ b/tests/Doctrine/Tests/DBAL/Mocks/MockPlatform.php @@ -10,9 +10,19 @@ class MockPlatform extends \Doctrine\DBAL\Platforms\AbstractPlatform public function getBigIntTypeDeclarationSql(array $columnDef) {} public function getSmallIntTypeDeclarationSql(array $columnDef) {} public function _getCommonIntegerTypeDeclarationSql(array $columnDef) {} - public function getVarcharTypeDeclarationSql(array $field) {} + + public function getVarcharTypeDeclarationSql(array $field) + { + return "DUMMYVARCHAR()"; + } + + public function getVarcharDefaultLength() + { + return 255; + } + public function getName() { return 'mock'; } -} \ 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 526485a6b..1b2f8426a 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/PostgreSqlPlatformTest.php @@ -80,12 +80,29 @@ class PostgreSqlPlatformTest extends \Doctrine\Tests\DbalTestCase ); } + public function testGeneratesForeignKeySqlForNonStandardOptions() + { + $definition = array( + 'name' => 'my_fk', + 'local' => 'foreign_id', + 'foreign' => 'id', + 'foreignTable' => 'my_table', + 'onDelete' => 'CASCADE' + ); + $this->assertEquals( + " CONSTRAINT my_fk FOREIGN KEY (foreign_id) REFERENCES my_table(id) ON DELETE CASCADE NOT DEFERRABLE INITIALLY IMMEDIATE", + $this->_platform->getForeignKeyDeclarationSql($definition) + ); + } + 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'); + $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() diff --git a/tests/Doctrine/Tests/DBAL/Types/StringTest.php b/tests/Doctrine/Tests/DBAL/Types/StringTest.php new file mode 100644 index 000000000..f67adbf0b --- /dev/null +++ b/tests/Doctrine/Tests/DBAL/Types/StringTest.php @@ -0,0 +1,31 @@ +_platform = new \Doctrine\Tests\DBAL\Mocks\MockPlatform(); + $this->_type = Type::getType('string'); + } + + public function testReturnsSqlDeclarationFromPlatformVarchar() + { + $this->assertEquals("DUMMYVARCHAR()", $this->_type->getSqlDeclaration(array(), $this->_platform)); + } + + public function testReturnsDefaultLengthFromPlatformVarchar() + { + $this->assertEquals(255, $this->_type->getDefaultLength($this->_platform)); + } +}