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
3f238c0a
Commit
3f238c0a
authored
Sep 24, 2013
by
Vladislav Vlastovskiy
Committed by
Benjamin Eberlei
Sep 26, 2013
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added test with alternative shard chooser
parent
37cc936e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
39 additions
and
0 deletions
+39
-0
PoolingShardManagerTest.php
.../Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php
+39
-0
No files found.
tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php
View file @
3f238c0a
...
@@ -36,6 +36,15 @@ class PoolingShardManagerTest extends \PHPUnit_Framework_TestCase
...
@@ -36,6 +36,15 @@ class PoolingShardManagerTest extends \PHPUnit_Framework_TestCase
return
$mock
;
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
()
public
function
testSelectGlobal
()
{
{
$conn
=
$this
->
createConnectionMock
();
$conn
=
$this
->
createConnectionMock
();
...
@@ -104,5 +113,35 @@ class PoolingShardManagerTest extends \PHPUnit_Framework_TestCase
...
@@ -104,5 +113,35 @@ class PoolingShardManagerTest extends \PHPUnit_Framework_TestCase
$this
->
assertEquals
(
array
(
array
(
'id'
=>
1
),
array
(
'id'
=>
2
)),
$result
);
$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