Skip to content

Commit

Permalink
Create failing tests for index creation in other schema for SQLite
Browse files Browse the repository at this point in the history
  • Loading branch information
greg0ire committed Nov 21, 2023
1 parent 0ac3c27 commit f944006
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
27 changes: 27 additions & 0 deletions tests/Functional/Platform/OtherSchemaTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Doctrine\DBAL\Tests\Functional\Platform;

use Doctrine\DBAL\Platforms\SqlitePlatform;
use Doctrine\DBAL\Schema\Table;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Types\Types;

class OtherSchemaTest extends FunctionalTestCase
{
public function testATableCanBeCreatedInAnotherSchema(): void
{
if (! ($this->connection->getDatabasePlatform() instanceof SqlitePlatform)) {
self::markTestSkipped('This test requires SQLite');
}

$this->connection->executeStatement("ATTACH DATABASE '/tmp/test_other_schema.sqlite' AS other");
$this->connection->getDatabasePlatform()->disableSchemaEmulation();

$table = new Table('other.test_other_schema');
$table->addColumn('id', Types::INTEGER);
$table->addIndex(['id']);

$this->dropAndCreateTable($table);
}
}
20 changes: 19 additions & 1 deletion tests/Platforms/SqlitePlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ class SqlitePlatformTest extends AbstractPlatformTestCase
{
public function createPlatform(): AbstractPlatform
{
return new SqlitePlatform();
$platform = new SqlitePlatform();
$platform->disableSchemaEmulation();

return $platform;
}

public function getGenerateTableSql(): string
Expand Down Expand Up @@ -768,4 +771,19 @@ public function testGetCreateTableSQLWithColumnCollation(): void
$this->platform->getCreateTableSQL($table),
);
}

public function testCreateTableInOtherSchema(): void
{
$table = new Table('other_schema.foo');
$table->addColumn('id', Types::INTEGER);
$table->addIndex(['id']);

self::assertSame(
[
'CREATE TABLE other_schema.foo (id INTEGER NOT NULL)',
'CREATE INDEX other_schema.IDX_8C73652176FF8CAA ON foo (id)',
],
$this->platform->getCreateTableSQL($table),
);
}
}

0 comments on commit f944006

Please sign in to comment.