Commit 3cf98859 authored by Benjamin Eberlei's avatar Benjamin Eberlei Committed by Adrien Brault

[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.

Conflicts:
	tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php
parent f15c4823
...@@ -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->connections['slave'] = $this->_conn = $this->connections['master'];
} else {
$this->_conn = $this->connections[$connectionName]; $this->_conn = $this->connections[$connectionName];
if ($forceMasterAsSlave && ! $this->keepSlave) {
$this->connections['slave'] = $this->_conn;
} }
return false; return false;
} }
......
...@@ -102,4 +102,23 @@ class MasterSlaveConnectionTest extends DbalFunctionalTestCase ...@@ -102,4 +102,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