Commit 6a932e3c authored by Marco Pivetta's avatar Marco Pivetta

Merge pull request #690 from adrienbrault/dbal-717-2.4

Cherry pick to 2.4: [DBAL-717] Fix bug in MasterSlaveConnection with keepSlave option and switch back after transaction.
parents f15c4823 3cf98859
......@@ -163,11 +163,12 @@ class MasterSlaveConnection extends Connection
}
if ($this->connections[$connectionName]) {
if ($forceMasterAsSlave) {
$this->connections['slave'] = $this->_conn = $this->connections['master'];
} else {
$this->_conn = $this->connections[$connectionName];
if ($forceMasterAsSlave && ! $this->keepSlave) {
$this->connections['slave'] = $this->_conn;
}
return false;
}
......
......@@ -102,4 +102,23 @@ class MasterSlaveConnectionTest extends DbalFunctionalTestCase
$conn->connect('slave');
$this->assertFalse($conn->isConnectedToMaster());
}
/**
* @group DBAL-335
*/
public function testKeepSlaveInsertStaysOnMaster()
{
$conn = $this->createMasterSlaveConnection($keepSlave = true);
$conn->connect('slave');
$conn->insert('master_slave_table', array('test_int' => 30));
$this->assertTrue($conn->isConnectedToMaster());
$conn->connect();
$this->assertTrue($conn->isConnectedToMaster());
$conn->connect('slave');
$this->assertFalse($conn->isConnectedToMaster());
}
}
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