Commit 269d3e1f authored by Benjamin Eberlei's avatar Benjamin Eberlei

[DBAL-717] Fix bug in MasterSlaveConnection with keepSlave option and switch...

[DBAL-717] Fix bug in MasterSlaveConnection with keepSlave option and switch back after transaction.
parent d6462810
......@@ -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;
}
......
......@@ -107,4 +107,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