Skip to content

Commit

Permalink
Test quoted qualified name
Browse files Browse the repository at this point in the history
The current behavior is that a quote in the table name should result in
the name being considered "quoted" and be passed to DBAL's
quoteIdentifier() method, which should quote each identifier
individually (so the dot is still interpreted as a schema separator).
  • Loading branch information
greg0ire committed Jan 26, 2025
1 parent c2a4932 commit fd780f7
Showing 1 changed file with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

declare(strict_types=1);

namespace Doctrine\Tests\ORM\Functional\Mapping;

use Doctrine\DBAL\Platforms\PostgreSQLPlatform;
use Doctrine\ORM\Mapping as ORM;
use Doctrine\ORM\Mapping\Driver\AttributeDriver;
use Doctrine\ORM\Tools\SchemaTool;
use Doctrine\Tests\OrmFunctionalTestCase;

class PostgreSqlDefaultQuoteStrategyTest extends OrmFunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();

$platform = $this->_em->getConnection()->getDatabasePlatform();
if (! $platform instanceof PostgreSQLPlatform) {
self::markTestSkipped(self::class . ' requires the use of postgresql.');
}

$this->_em = $this->getEntityManager(
null,
new AttributeDriver([__DIR__], true)
);
$this->_schemaTool = new SchemaTool($this->_em);
}

public function testQuotingStillAllowsInterpretingDotAsSchemaSeparator(): void
{
$this->createSchemaForModels(Product::class);
$schemaManager = $this->createSchemaManager();
self::assertContains(
'Inventory',
$schemaManager->listSchemaNames(),
'"Inventory" should be interpreted as a schema name, even when quoted.'
);
self::assertContains(
'Products',
$schemaManager->listTableNames(),
'"Products" should be interpreted as a table name, even when quoted.'
);
}
}

#[ORM\Entity]
#[ORM\Table(name: '"Inventory.Products"')] // Using quotes to make sure capitalization is preserved
class Product
{
#[ORM\Id]
public ?int $id = null;
}

0 comments on commit fd780f7

Please sign in to comment.