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 ...@@ -163,11 +163,12 @@ class MasterSlaveConnection extends Connection
} }
if ($this->connections[$connectionName]) { if ($this->connections[$connectionName]) {
if ($forceMasterAsSlave) { $this->_conn = $this->connections[$connectionName];
$this->connections['slave'] = $this->_conn = $this->connections['master'];
} else { if ($forceMasterAsSlave && ! $this->keepSlave) {
$this->_conn = $this->connections[$connectionName]; $this->connections['slave'] = $this->_conn;
} }
return false; return false;
} }
......
...@@ -94,7 +94,7 @@ class MasterSlaveConnectionTest extends DbalFunctionalTestCase ...@@ -94,7 +94,7 @@ class MasterSlaveConnectionTest extends DbalFunctionalTestCase
{ {
$conn = $this->createMasterSlaveConnection($keepSlave = true); $conn = $this->createMasterSlaveConnection($keepSlave = true);
$conn->connect('slave'); $conn->connect('slave');
$conn->beginTransaction(); $conn->beginTransaction();
$conn->insert('master_slave_table', array('test_int' => 30)); $conn->insert('master_slave_table', array('test_int' => 30));
$conn->commit(); $conn->commit();
...@@ -107,4 +107,23 @@ class MasterSlaveConnectionTest extends DbalFunctionalTestCase ...@@ -107,4 +107,23 @@ class MasterSlaveConnectionTest extends DbalFunctionalTestCase
$conn->connect('slave'); $conn->connect('slave');
$this->assertFalse($conn->isConnectedToMaster()); $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