Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Doctrine/SchemaConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ private function ensurePostgreSql(): void
private function applySearchPath(string $schema): void
{
if ($this->_conn !== null) {
$schema = $this->getDatabasePlatform()->quoteIdentifier($schema);

$this->_conn->exec('SET search_path TO ' . $schema);
}
}
Expand Down
34 changes: 33 additions & 1 deletion tests/Doctrine/SchemaConnectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function testConnectSetsSearchPath(): void

$driverConnection->expects($this->once())
->method('exec')
->with('SET search_path TO test_schema');
->with('SET search_path TO "test_schema"');

$driver = $this->createMock(Driver::class);

Expand All @@ -49,6 +49,38 @@ public function testConnectSetsSearchPath(): void
self::assertTrue($result);
}

public function testConnectSetsSearchPathWithSpecialChars(): void
{
$driverConnection = $this->createMock(DriverConnection::class);

$driverConnection->expects($this->once())
->method('exec')
->with('SET search_path TO "test-schema/foo"');

$driver = $this->createMock(Driver::class);

$driver->method('connect')->willReturn($driverConnection);

$platform = new PostgreSQLPlatform();
$connection = $this->getMockBuilder(SchemaConnection::class)
->setConstructorArgs([[], $driver, new Configuration(), new EventManager()])
->onlyMethods(['getDatabasePlatform', 'fetchOne'])
->getMock();

$connection->method('getDatabasePlatform')->willReturn($platform);
$connection->method('fetchOne')->willReturn(true);

$resolver = new BaggageSchemaResolver();

$resolver->setSchema('test-schema/foo');

SchemaConnection::setSchemaResolver($resolver);

$result = $connection->connect();

self::assertTrue($result);
}

public function testConnectSkipsWhenNoSchema(): void
{
$driverConnection = $this->createMock(DriverConnection::class);
Expand Down
Loading