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
c614747c
Unverified
Commit
c614747c
authored
Dec 27, 2016
by
Maximilian Ruta
Committed by
Luís Cobucci
Nov 19, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Inherit charset from master connection if not set explicitly
parent
63115676
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
49 additions
and
5 deletions
+49
-5
MasterSlaveConnection.php
lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php
+8
-2
MasterSlaveConnectionTest.php
...trine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php
+41
-3
No files found.
lib/Doctrine/DBAL/Connections/MasterSlaveConnection.php
View file @
c614747c
...
...
@@ -224,7 +224,13 @@ class MasterSlaveConnection extends Connection
return
$params
[
'master'
];
}
return
$params
[
'slaves'
][
array_rand
(
$params
[
'slaves'
])];
$config
=
$params
[
'slaves'
][
array_rand
(
$params
[
'slaves'
])];
if
(
!
isset
(
$config
[
'charset'
])
&&
isset
(
$params
[
'master'
][
'charset'
]))
{
$config
[
'charset'
]
=
$params
[
'master'
][
'charset'
];
}
return
$config
;
}
/**
...
...
tests/Doctrine/Tests/DBAL/Functional/MasterSlaveConnectionTest.php
View file @
c614747c
...
...
@@ -2,6 +2,7 @@
namespace
Doctrine\Tests\DBAL\Functional
;
use
Doctrine\DBAL\Connections\MasterSlaveConnection
;
use
Doctrine\DBAL\DriverManager
;
use
Doctrine\Tests\DbalFunctionalTestCase
;
...
...
@@ -38,15 +39,52 @@ class MasterSlaveConnectionTest extends DbalFunctionalTestCase
$this
->
_conn
->
insert
(
'master_slave_table'
,
array
(
'test_int'
=>
1
));
}
public
function
createMasterSlaveConnection
(
$keepSlave
=
false
)
private
function
createMasterSlaveConnection
(
bool
$keepSlave
=
false
)
:
MasterSlaveConnection
{
return
DriverManager
::
getConnection
(
$this
->
createMasterSlaveConnectionParams
(
$keepSlave
));
}
private
function
createMasterSlaveConnectionParams
(
bool
$keepSlave
=
false
)
:
array
{
$params
=
$this
->
_conn
->
getParams
();
$params
[
'master'
]
=
$params
;
$params
[
'slaves'
]
=
array
(
$params
,
$params
);
$params
[
'keepSlave'
]
=
$keepSlave
;
$params
[
'wrapperClass'
]
=
'Doctrine\DBAL\Connections\MasterSlaveConnection'
;
$params
[
'wrapperClass'
]
=
MasterSlaveConnection
::
class
;
return
$params
;
}
return
DriverManager
::
getConnection
(
$params
);
public
function
testInheritCharsetFromMaster
()
:
void
{
$charsets
=
[
'utf8'
,
'latin1'
];
foreach
(
$charsets
as
$charset
)
{
$params
=
$this
->
createMasterSlaveConnectionParams
();
$params
[
'master'
][
'charset'
]
=
$charset
;
foreach
(
$params
[
'slaves'
]
as
$index
=>
$slaveParams
)
{
if
(
isset
(
$slaveParams
[
'charset'
]))
{
unset
(
$params
[
'slaves'
][
$index
][
'charset'
]);
}
}
/** @var MasterSlaveConnection $conn */
$conn
=
DriverManager
::
getConnection
(
$params
);
$conn
->
connect
(
'slave'
);
self
::
assertFalse
(
$conn
->
isConnectedToMaster
());
$clientCharset
=
$conn
->
fetchColumn
(
'select @@character_set_client as c'
);
self
::
assertSame
(
$charset
,
substr
(
strtolower
(
$clientCharset
),
0
,
strlen
(
$charset
))
);
}
}
public
function
testMasterOnConnect
()
...
...
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