Commit f0a19f7a authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge branch 'DBAL-168' into 2.1.x

parents 64329fcb f1feed0f
...@@ -210,8 +210,7 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -210,8 +210,7 @@ class PostgreSqlPlatform extends AbstractPlatform
( (
SELECT c.oid SELECT c.oid
FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n FROM pg_catalog.pg_class c, pg_catalog.pg_namespace n
WHERE " .$this->getTableWhereClause($table) ." WHERE " .$this->getTableWhereClause($table) ." AND n.oid = c.relnamespace
AND n.oid = c.relnamespace
) )
AND r.contype = 'f'"; AND r.contype = 'f'";
} }
...@@ -259,15 +258,22 @@ class PostgreSqlPlatform extends AbstractPlatform ...@@ -259,15 +258,22 @@ class PostgreSqlPlatform extends AbstractPlatform
) AND pg_index.indexrelid = oid"; ) AND pg_index.indexrelid = oid";
} }
/**
* @param string $table
* @param string $classAlias
* @param string $namespaceAlias
* @return string
*/
private function getTableWhereClause($table, $classAlias = 'c', $namespaceAlias = 'n') private function getTableWhereClause($table, $classAlias = 'c', $namespaceAlias = 'n')
{ {
$whereClause = ""; $whereClause = $namespaceAlias.".nspname NOT IN ('pg_catalog', 'information_schema', 'pg_toast') AND ";
if (strpos($table, ".") !== false) { if (strpos($table, ".") !== false) {
list($schema, $table) = explode(".", $table); list($schema, $table) = explode(".", $table);
$whereClause = "$classAlias.relname = '" . $table . "' AND $namespaceAlias.nspname = '" . $schema . "'"; $whereClause .= "$classAlias.relname = '" . $table . "' AND $namespaceAlias.nspname = '" . $schema . "'";
} else { } else {
$whereClause = "$classAlias.relname = '" . $table . "'"; $whereClause .= "$classAlias.relname = '" . $table . "'";
} }
return $whereClause; return $whereClause;
} }
......
...@@ -250,7 +250,7 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest ...@@ -250,7 +250,7 @@ class SchemaManagerFunctionalTestCase extends \Doctrine\Tests\DbalFunctionalTest
$this->assertEquals(1, count($fkConstraints), "Table 'test_create_fk1' has to have one foreign key."); $this->assertEquals(1, count($fkConstraints), "Table 'test_create_fk1' has to have one foreign key.");
$fkConstraint = current($fkConstraints); $fkConstraint = current($fkConstraints);
$this->assertType('\Doctrine\DBAL\Schema\ForeignKeyConstraint', $fkConstraint); $this->assertInstanceOf('\Doctrine\DBAL\Schema\ForeignKeyConstraint', $fkConstraint);
$this->assertEquals('test_foreign', strtolower($fkConstraint->getForeignTableName())); $this->assertEquals('test_foreign', strtolower($fkConstraint->getForeignTableName()));
$this->assertEquals(array('foreign_key_test'), array_map('strtolower', $fkConstraint->getColumns())); $this->assertEquals(array('foreign_key_test'), array_map('strtolower', $fkConstraint->getColumns()));
$this->assertEquals(array('id'), array_map('strtolower', $fkConstraint->getForeignColumns())); $this->assertEquals(array('id'), array_map('strtolower', $fkConstraint->getForeignColumns()));
......
...@@ -11,7 +11,7 @@ class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -11,7 +11,7 @@ class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase
/** /**
* SQLITE does not support databases. * SQLITE does not support databases.
* *
* @expectedException \Exception * @expectedException Doctrine\DBAL\DBALException
*/ */
public function testListDatabases() public function testListDatabases()
{ {
...@@ -29,29 +29,7 @@ class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase ...@@ -29,29 +29,7 @@ class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase
} }
/** /**
* @expectedException \Exception * @expectedException Doctrine\DBAL\DBALException
*/
// This test is not correct. createSequence expects an object.
// PHPUnit wrapping the PHP error in an exception hides this but it shows up
// when the tests are run in the build (phing).
/*public function testCreateSequence()
{
$this->_sm->createSequence('seqname', 1, 1);
}*/
/**
* @expectedException \Exception
*/
// This test is not correct. createForeignKey expects an object.
// PHPUnit wrapping the PHP error in an exception hides this but it shows up
// when the tests are run in the build (phing).
/*public function testCreateForeignKey()
{
$this->_sm->createForeignKey('table', array());
}*/
/**
* @expectedException \Exception
*/ */
public function testRenameTable() public function testRenameTable()
{ {
......
<?php
namespace Doctrine\Tests\DBAL\Functional\Ticket;
/**
* @group DBAL-168
*/
class DBAL168Test extends \Doctrine\Tests\DbalFunctionalTestCase
{
public function testDomainsTable()
{
if ($this->_conn->getDatabasePlatform()->getName() != "postgresql") {
$this->markTestSkipped('PostgreSQL only test');
}
$table = new \Doctrine\DBAL\Schema\Table("domains");
$table->addColumn('id', 'integer');
$table->addColumn('parent_id', 'integer');
$table->setPrimaryKey(array('id'));
$table->addForeignKeyConstraint('domains', array('parent_id'), array('id'));
$this->_conn->getSchemaManager()->createTable($table);
$table = $this->_conn->getSchemaManager()->listTableDetails('domains');
$this->assertEquals('domains', $table->getName());
}
}
\ No newline at end of file
...@@ -81,7 +81,11 @@ class TypeConversionTest extends \Doctrine\Tests\DbalFunctionalTestCase ...@@ -81,7 +81,11 @@ class TypeConversionTest extends \Doctrine\Tests\DbalFunctionalTestCase
$sql = "SELECT " . $columnName . " FROM type_conversion WHERE id = " . self::$typeCounter; $sql = "SELECT " . $columnName . " FROM type_conversion WHERE id = " . self::$typeCounter;
$actualDbValue = $typeInstance->convertToPHPValue($this->_conn->fetchColumn($sql), $this->_conn->getDatabasePlatform()); $actualDbValue = $typeInstance->convertToPHPValue($this->_conn->fetchColumn($sql), $this->_conn->getDatabasePlatform());
$this->assertType($expectedPhpType, $actualDbValue, "The expected type from the conversion to and back from the database should be " . $expectedPhpType); if ($originalValue instanceof \DateTime) {
$this->assertInstanceOf($expectedPhpType, $actualDbValue, "The expected type from the conversion to and back from the database should be " . $expectedPhpType);
} else {
$this->assertInternalType($expectedPhpType, $actualDbValue, "The expected type from the conversion to and back from the database should be " . $expectedPhpType);
}
if ($type !== "datetimetz") { if ($type !== "datetimetz") {
$this->assertEquals($originalValue, $actualDbValue, "Conversion between values should produce the same out as in value, but doesnt!"); $this->assertEquals($originalValue, $actualDbValue, "Conversion between values should produce the same out as in value, but doesnt!");
......
...@@ -156,7 +156,7 @@ class MsSqlPlatformTest extends AbstractPlatformTestCase ...@@ -156,7 +156,7 @@ class MsSqlPlatformTest extends AbstractPlatformTestCase
public function testModifyLimitQueryWithOffset() public function testModifyLimitQueryWithOffset()
{ {
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user ORDER BY username DESC', 10, 5); $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user ORDER BY username DESC', 10, 5);
$this->assertEquals('WITH outer_tbl AS (SELECT ROW_NUMBER() OVER (ORDER BY username DESC) AS "doctrine_rownum", * FROM (SELECT * FROM user) AS inner_tbl) SELECT * FROM outer_tbl WHERE "doctrine_rownum" BETWEEN 6 AND 15', $sql); $this->assertEquals('SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY username DESC) AS "doctrine_rownum", * FROM user) AS doctrine_tbl WHERE "doctrine_rownum" BETWEEN 6 AND 15', $sql);
} }
public function testModifyLimitQueryWithAscOrderBy() public function testModifyLimitQueryWithAscOrderBy()
......
...@@ -24,7 +24,7 @@ class DateTimeTest extends \Doctrine\Tests\DbalTestCase ...@@ -24,7 +24,7 @@ class DateTimeTest extends \Doctrine\Tests\DbalTestCase
$date = new \DateTime('1985-09-01 10:10:10'); $date = new \DateTime('1985-09-01 10:10:10');
$expected = $date->format($this->_platform->getDateTimeTzFormatString()); $expected = $date->format($this->_platform->getDateTimeTzFormatString());
$actual = is_string($this->_type->convertToDatabaseValue($date, $this->_platform)); $actual = $this->_type->convertToDatabaseValue($date, $this->_platform);
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
} }
......
...@@ -24,7 +24,7 @@ class DateTimeTzTest extends \Doctrine\Tests\DbalTestCase ...@@ -24,7 +24,7 @@ class DateTimeTzTest extends \Doctrine\Tests\DbalTestCase
$date = new \DateTime('1985-09-01 10:10:10'); $date = new \DateTime('1985-09-01 10:10:10');
$expected = $date->format($this->_platform->getDateTimeTzFormatString()); $expected = $date->format($this->_platform->getDateTimeTzFormatString());
$actual = is_string($this->_type->convertToDatabaseValue($date, $this->_platform)); $actual = $this->_type->convertToDatabaseValue($date, $this->_platform);
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
} }
......
...@@ -27,7 +27,7 @@ class VarDateTimeTest extends \Doctrine\Tests\DbalTestCase ...@@ -27,7 +27,7 @@ class VarDateTimeTest extends \Doctrine\Tests\DbalTestCase
$date = new \DateTime('1985-09-01 10:10:10'); $date = new \DateTime('1985-09-01 10:10:10');
$expected = $date->format($this->_platform->getDateTimeTzFormatString()); $expected = $date->format($this->_platform->getDateTimeTzFormatString());
$actual = is_string($this->_type->convertToDatabaseValue($date, $this->_platform)); $actual = $this->_type->convertToDatabaseValue($date, $this->_platform);
$this->assertEquals($expected, $actual); $this->assertEquals($expected, $actual);
} }
......
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