Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore SqlitePlatform#supportsForeignKeyConstraints (no lies!) #242

Merged
merged 3 commits into from Jan 7, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
Expand Up @@ -602,6 +602,14 @@ public function canEmulateSchemas()
return true;
}

/**
* {@inheritDoc}
*/
public function supportsForeignKeyConstraints()
{
return false;
}

/**
* {@inheritDoc}
*/
Expand Down
Expand Up @@ -433,12 +433,14 @@ public function testAlterTableScenario()
// dont check for index size here, some platforms automatically add indexes for foreign keys.
$this->assertFalse($table->hasIndex('foo_idx'));

$this->assertEquals(1, count($table->getForeignKeys()));
$fks = $table->getForeignKeys();
$foreignKey = current($fks);
$this->assertEquals('alter_table_foreign', strtolower($foreignKey->getForeignTableName()));
$this->assertEquals(array('foreign_key_test'), array_map('strtolower', $foreignKey->getColumns()));
$this->assertEquals(array('id'), array_map('strtolower', $foreignKey->getForeignColumns()));
if ($this->_sm->getDatabasePlatform()->supportsForeignKeyConstraints()) {
$fks = $table->getForeignKeys();
$this->assertCount(1, $fks);
$foreignKey = current($fks);
$this->assertEquals('alter_table_foreign', strtolower($foreignKey->getForeignTableName()));
$this->assertEquals(array('foreign_key_test'), array_map('strtolower', $foreignKey->getColumns()));
$this->assertEquals(array('id'), array_map('strtolower', $foreignKey->getForeignColumns()));
}
}

public function testCreateAndListViews()
Expand Down
17 changes: 16 additions & 1 deletion tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
Expand Up @@ -10,7 +10,7 @@
abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
{
/**
* @var Doctrine\DBAL\Platforms\AbstractPlatform
* @var \Doctrine\DBAL\Platforms\AbstractPlatform
*/
protected $_platform;

Expand Down Expand Up @@ -156,6 +156,21 @@ public function testGeneratesConstraintCreationSql()
$this->assertEquals($this->getGenerateConstraintForeignKeySql(), $sql);
}

public function testGeneratesForeignKeySqlOnlyWhenSupportingForeignKeys()
{
$fk = new \Doctrine\DBAL\Schema\ForeignKeyConstraint(array('fk_name'), 'foreign', array('id'), 'constraint_fk');

if ($this->_platform->supportsForeignKeyConstraints()) {
$this->assertInternalType(
'string',
$this->_platform->getCreateForeignKeySQL($fk, 'test')
);
} else {
$this->setExpectedException('Doctrine\DBAL\DBALException');
$this->_platform->getCreateForeignKeySQL($fk, 'test');
}
}

protected function getBitAndComparisonExpressionSql($value1, $value2)
{
return '(' . $value1 . ' & ' . $value2 . ')';
Expand Down