Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
D
doctrine-dbal
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Tomáš Trávníček
doctrine-dbal
Commits
1f7ef808
Commit
1f7ef808
authored
Dec 19, 2011
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'MasterSlave'
parents
a9eb7b48
e7d6fc2c
Changes
5
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
443 additions
and
21 deletions
+443
-21
MasterSlaveConnection.php
lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php
+328
-0
DriverManager.php
lib/Doctrine/DBAL/DriverManager.php
+22
-19
LoggingTest.php
tests/Doctrine/Tests/DBAL/Functional/LoggingTest.php
+0
-2
MasterSlaveConnectionTest.php
...trine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php
+82
-0
MasterSlaveTest.php
tests/Doctrine/Tests/DBAL/Functional/MasterSlaveTest.php
+11
-0
No files found.
lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php
0 → 100644
View file @
1f7ef808
This diff is collapsed.
Click to expand it.
lib/Doctrine/DBAL/DriverManager.php
View file @
1f7ef808
...
@@ -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.
...
...
tests/Doctrine/Tests/DBAL/Functional/LoggingTest.php
View file @
1f7ef808
...
@@ -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
()
...
...
tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php
0 → 100644
View file @
1f7ef808
<?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
());
}
}
tests/Doctrine/Tests/DBAL/Functional/MasterSlaveTest.php
0 → 100644
View file @
1f7ef808
<?php
namespace
Doctrine\Tests\DBAL\Functional
;
class
MasterSlaveTest
extends
\Doctrine\Tests\DbalFunctionalTestCase
{
public
function
test
()
{
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment