Skip to content

Commit 3af82f6

Browse files
authored
[8.x] Add tests for new changes in postgres connector (#40800)
1 parent 09c1c04 commit 3af82f6

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tests/Database/DatabaseConnectorTest.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,23 @@ public function testPostgresApplicationNameIsSet()
140140
$this->assertSame($result, $connection);
141141
}
142142

143+
public function testPostgresConnectorReadsIsolationLevelFromConfig()
144+
{
145+
$dsn = 'pgsql:host=foo;dbname=\'bar\';port=111';
146+
$config = ['host' => 'foo', 'database' => 'bar', 'port' => 111, 'isolation_level' => 'SERIALIZABLE'];
147+
$connector = $this->getMockBuilder(PostgresConnector::class)->onlyMethods(['createConnection', 'getOptions'])->getMock();
148+
$connection = m::mock(PDO::class);
149+
$connector->expects($this->once())->method('getOptions')->with($this->equalTo($config))->willReturn(['options']);
150+
$connector->expects($this->once())->method('createConnection')->with($this->equalTo($dsn), $this->equalTo($config), $this->equalTo(['options']))->willReturn($connection);
151+
$statement = m::mock(PDOStatement::class);
152+
$connection->shouldReceive('prepare')->once()->with('set session characteristics as transaction isolation level SERIALIZABLE')->andReturn($statement);
153+
$statement->shouldReceive('execute')->zeroOrMoreTimes();
154+
$connection->shouldReceive('exec')->zeroOrMoreTimes();
155+
$result = $connector->connect($config);
156+
157+
$this->assertSame($result, $connection);
158+
}
159+
143160
public function testSQLiteMemoryDatabasesMayBeConnectedTo()
144161
{
145162
$dsn = 'sqlite::memory:';

0 commit comments

Comments
 (0)