Unverified Commit f20ba141 authored by Grégoire Paris's avatar Grégoire Paris Committed by GitHub

Merge pull request #3994 from greg0ire/check-for-alter-support-fk

Use proper check in acceptForeignKey()
parents 61a6b9b9 f0c1af4b
......@@ -55,7 +55,7 @@ class CreateSchemaSqlCollector extends AbstractVisitor
*/
public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint)
{
if (! $this->platform->supportsForeignKeyConstraints()) {
if (! $this->platform->supportsCreateDropForeignKeyConstraints()) {
return;
}
......
<?php
declare(strict_types=1);
namespace Doctrine\Tests\DBAL\Functional\Schema;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Tests\DbalFunctionalTestCase;
class ForeignKeyTest extends DbalFunctionalTestCase
{
public function testCreatingATableWithAForeignKey() : void
{
$schema = new Schema();
$referencedTable = $schema->createTable('referenced_table');
$referencedTable->addColumn('id', 'integer');
$referencedTable->setPrimaryKey(['id']);
$referencingTable = $schema->createTable('referencing_table');
$referencingTable->addColumn('referenced_id', 'integer');
$referencingTable->addForeignKeyConstraint(
$referencedTable,
['referenced_id'],
['id']
);
foreach ($schema->toSql($this->connection->getDatabasePlatform()) as $sql) {
$this->connection->exec($sql);
}
self::assertCount(
1,
$this->connection->getSchemaManager()->listTableForeignKeys('referencing_table')
);
}
}
......@@ -29,7 +29,7 @@ class CreateSchemaSqlCollectorTest extends TestCase
'getCreateSchemaSQL',
'getCreateSequenceSQL',
'getCreateTableSQL',
'supportsForeignKeyConstraints',
'supportsCreateDropForeignKeyConstraints',
'supportsSchemas',
]
)
......@@ -76,11 +76,11 @@ class CreateSchemaSqlCollectorTest extends TestCase
public function testAcceptsForeignKey() : void
{
$this->platformMock->expects($this->at(0))
->method('supportsForeignKeyConstraints')
->method('supportsCreateDropForeignKeyConstraints')
->will($this->returnValue(false));
$this->platformMock->expects($this->at(1))
->method('supportsForeignKeyConstraints')
->method('supportsCreateDropForeignKeyConstraints')
->will($this->returnValue(true));
$table = $this->createTableMock();
......@@ -106,7 +106,7 @@ class CreateSchemaSqlCollectorTest extends TestCase
public function testResetsQueries() : void
{
foreach (['supportsSchemas', 'supportsForeignKeyConstraints'] as $method) {
foreach (['supportsSchemas', 'supportsCreateDropForeignKeyConstraints'] as $method) {
$this->platformMock->expects($this->any())
->method($method)
->will($this->returnValue(true));
......
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