Commit 1f7ef808 authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge branch 'MasterSlave'

parents a9eb7b48 e7d6fc2c
This diff is collapsed.
...@@ -87,6 +87,9 @@ final class DriverManager ...@@ -87,6 +87,9 @@ final class DriverManager
* You may specify a custom wrapper class through the 'wrapperClass' * You may specify a custom wrapper class through the 'wrapperClass'
* parameter but this class MUST inherit from Doctrine\DBAL\Connection. * parameter but this class MUST inherit from Doctrine\DBAL\Connection.
* *
* <b>driverClass</b>:
* The driver class to use.
*
* @param array $params The parameters. * @param array $params The parameters.
* @param Doctrine\DBAL\Configuration The configuration to use. * @param Doctrine\DBAL\Configuration The configuration to use.
* @param Doctrine\Common\EventManager The event manager to use. * @param Doctrine\Common\EventManager The event manager to use.
......
...@@ -2,8 +2,6 @@ ...@@ -2,8 +2,6 @@
namespace Doctrine\Tests\DBAL\Functional; namespace Doctrine\Tests\DBAL\Functional;
require_once __DIR__ . '/../../TestInit.php';
class LoggingTest extends \Doctrine\Tests\DbalFunctionalTestCase class LoggingTest extends \Doctrine\Tests\DbalFunctionalTestCase
{ {
public function testLogExecuteQuery() public function testLogExecuteQuery()
......
<?php
namespace Doctrine\Tests\DBAL\Functional;
use Doctrine\Tests\DbalFunctionalTestCase;
use Doctrine\DBAL\DriverManager;
/**
* @group DBAL-20
*/
class MasterSlaveConnectionTest extends DbalFunctionalTestCase
{
public function setUp()
{
parent::setUp();
if ($this->_conn->getDatabasePlatform()->getName() == "sqlite") {
$this->markTestSkipped('Test does not work on sqlite.');
}
try {
/* @var $sm \Doctrine\DBAL\Schema\AbstractSchemaManager */
$table = new \Doctrine\DBAL\Schema\Table("master_slave_table");
$table->addColumn('test_int', 'integer');
$table->setPrimaryKey(array('test_int'));
$sm = $this->_conn->getSchemaManager();
$sm->createTable($table);
$this->_conn->insert('master_slave_table', array('test_int' => 1));
} catch(\Exception $e) {
}
}
public function createMasterSlaveConnection()
{
$params = $this->_conn->getParams();
$params['master'] = $params;
$params['slaves'] = array($params, $params);
$params['wrapperClass'] = 'Doctrine\DBAL\Connections\MasterSlaveConnection';
return DriverManager::getConnection($params);
}
public function testMasterOnConnect()
{
$conn = $this->createMasterSlaveConnection();
$this->assertFalse($conn->isConnectedToMaster());
$conn->connect('slave');
$this->assertFalse($conn->isConnectedToMaster());
$conn->connect('master');
$this->assertTrue($conn->isConnectedToMaster());
}
public function testNoMasterOnExecuteQuery()
{
$conn = $this->createMasterSlaveConnection();
$sql = "SELECT count(*) as num FROM master_slave_table";
$data = $conn->fetchAll($sql);
$data[0] = array_change_key_case($data[0], CASE_LOWER);
$this->assertEquals(1, $data[0]['num']);
$this->assertFalse($conn->isConnectedToMaster());
}
public function testMasterOnWriteOperation()
{
$conn = $this->createMasterSlaveConnection();
$conn->insert('master_slave_table', array('test_int' => 30));
$this->assertTrue($conn->isConnectedToMaster());
$sql = "SELECT count(*) as num FROM master_slave_table";
$data = $conn->fetchAll($sql);
$data[0] = array_change_key_case($data[0], CASE_LOWER);
$this->assertEquals(2, $data[0]['num']);
$this->assertTrue($conn->isConnectedToMaster());
}
}
<?php
namespace Doctrine\Tests\DBAL\Functional;
class MasterSlaveTest extends \Doctrine\Tests\DbalFunctionalTestCase
{
public function test()
{
}
}
\ No newline at end of file
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