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
59c310ba
Commit
59c310ba
authored
Sep 26, 2013
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'DDC-613' into 2.3
parents
2addbddb
3f238c0a
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
1 deletion
+40
-1
PoolingShardManager.php
lib/Doctrine/DBAL/Sharding/PoolingShardManager.php
+1
-1
PoolingShardManagerTest.php
.../Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php
+39
-0
No files found.
lib/Doctrine/DBAL/Sharding/PoolingShardManager.php
View file @
59c310ba
...
...
@@ -80,7 +80,7 @@ class PoolingShardManager implements ShardManager
$oldDistribution
=
$this
->
getCurrentDistributionValue
();
foreach
(
$shards
as
$shard
)
{
$this
->
selectShard
(
$shard
[
'id'
]);
$this
->
conn
->
connect
(
$shard
[
'id'
]);
foreach
(
$this
->
conn
->
fetchAll
(
$sql
,
$params
,
$types
)
as
$row
)
{
$result
[]
=
$row
;
}
...
...
tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php
View file @
59c310ba
...
...
@@ -36,6 +36,15 @@ class PoolingShardManagerTest extends \PHPUnit_Framework_TestCase
return
$mock
;
}
private
function
createStaticShardChoser
()
{
$mock
=
$this
->
getMock
(
'Doctrine\DBAL\Sharding\ShardChoser\ShardChoser'
);
$mock
->
expects
(
$this
->
any
())
->
method
(
'pickShard'
)
->
will
(
$this
->
returnCallback
(
function
(
$value
)
{
return
1
;
}));
return
$mock
;
}
public
function
testSelectGlobal
()
{
$conn
=
$this
->
createConnectionMock
();
...
...
@@ -104,5 +113,35 @@ class PoolingShardManagerTest extends \PHPUnit_Framework_TestCase
$this
->
assertEquals
(
array
(
array
(
'id'
=>
1
),
array
(
'id'
=>
2
)),
$result
);
}
public
function
testQueryAllWithStaticShardChoser
()
{
$sql
=
"SELECT * FROM table"
;
$params
=
array
(
1
);
$types
=
array
(
1
);
$conn
=
$this
->
createConnectionMock
();
$conn
->
expects
(
$this
->
at
(
0
))
->
method
(
'getParams'
)
->
will
(
$this
->
returnValue
(
array
(
'shards'
=>
array
(
array
(
'id'
=>
1
),
array
(
'id'
=>
2
)
),
'shardChoser'
=>
$this
->
createStaticShardChoser
())
));
$conn
->
expects
(
$this
->
at
(
1
))
->
method
(
'getParams'
)
->
will
(
$this
->
returnValue
(
array
(
'shards'
=>
array
(
array
(
'id'
=>
1
),
array
(
'id'
=>
2
)
),
'shardChoser'
=>
$this
->
createStaticShardChoser
())
));
$conn
->
expects
(
$this
->
at
(
2
))
->
method
(
'connect'
)
->
with
(
$this
->
equalTo
(
1
));
$conn
->
expects
(
$this
->
at
(
3
))
->
method
(
'fetchAll'
)
->
with
(
$this
->
equalTo
(
$sql
),
$this
->
equalTo
(
$params
),
$this
->
equalTo
(
$types
))
->
will
(
$this
->
returnValue
(
array
(
array
(
'id'
=>
1
)
)
));
$conn
->
expects
(
$this
->
at
(
4
))
->
method
(
'connect'
)
->
with
(
$this
->
equalTo
(
2
));
$conn
->
expects
(
$this
->
at
(
5
))
->
method
(
'fetchAll'
)
->
with
(
$this
->
equalTo
(
$sql
),
$this
->
equalTo
(
$params
),
$this
->
equalTo
(
$types
))
->
will
(
$this
->
returnValue
(
array
(
array
(
'id'
=>
2
)
)
));
$shardManager
=
new
PoolingShardManager
(
$conn
,
$this
->
createStaticShardChoser
());
$result
=
$shardManager
->
queryAll
(
$sql
,
$params
,
$types
);
$this
->
assertEquals
(
array
(
array
(
'id'
=>
1
),
array
(
'id'
=>
2
)),
$result
);
}
}
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