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
b6f48e1a
Commit
b6f48e1a
authored
Jun 26, 2012
by
Benjamin Eberlei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove PoolingShardConnection#getShardManager() method and refactored code. Fixed tests
parent
12f381f1
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
25 deletions
+26
-25
PoolingShardConnection.php
lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php
+4
-10
PoolingShardManager.php
lib/Doctrine/DBAL/Sharding/PoolingShardManager.php
+4
-3
SingleDatabaseSynchronizerTest.php
...AL/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php
+2
-2
PoolingShardManagerTest.php
.../Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php
+16
-10
No files found.
lib/Doctrine/DBAL/Sharding/PoolingShardConnection.php
View file @
b6f48e1a
...
@@ -126,17 +126,11 @@ class PoolingShardConnection extends Connection
...
@@ -126,17 +126,11 @@ class PoolingShardConnection extends Connection
}
}
/**
/**
* @return \Doctrine\DBAL\Sharding\PoolingShardManager
* Connect to a given shard
*
* @param mixed $shardId
* @return bool
*/
*/
public
function
getShardManager
()
{
if
(
$this
->
shardManager
===
null
)
{
$params
=
$this
->
getParams
();
$this
->
shardManager
=
new
PoolingShardManager
(
$this
,
$params
[
'shardChoser'
]);
}
return
$this
->
shardManager
;
}
public
function
connect
(
$shardId
=
null
)
public
function
connect
(
$shardId
=
null
)
{
{
if
(
$shardId
===
null
&&
$this
->
_conn
)
{
if
(
$shardId
===
null
&&
$this
->
_conn
)
{
...
...
lib/Doctrine/DBAL/Sharding/PoolingShardManager.php
View file @
b6f48e1a
...
@@ -32,10 +32,11 @@ class PoolingShardManager implements ShardManager
...
@@ -32,10 +32,11 @@ class PoolingShardManager implements ShardManager
private
$choser
;
private
$choser
;
private
$currentDistributionValue
;
private
$currentDistributionValue
;
public
function
__construct
(
PoolingShardConnection
$conn
,
ShardChoser
$choser
)
public
function
__construct
(
PoolingShardConnection
$conn
)
{
{
$this
->
conn
=
$conn
;
$params
=
$conn
->
getParams
();
$this
->
choser
=
$choser
;
$this
->
conn
=
$conn
;
$this
->
choser
=
$params
[
'shardChoser'
];
}
}
public
function
selectGlobal
()
public
function
selectGlobal
()
...
...
tests/Doctrine/Tests/DBAL/Schema/Synchronizer/SingleDatabaseSynchronizerTest.php
View file @
b6f48e1a
...
@@ -45,7 +45,7 @@ class SingleDatabaseSynchronizerTest extends \PHPUnit_Framework_TestCase
...
@@ -45,7 +45,7 @@ class SingleDatabaseSynchronizerTest extends \PHPUnit_Framework_TestCase
$table
->
setPrimaryKey
(
array
(
'id'
));
$table
->
setPrimaryKey
(
array
(
'id'
));
$sql
=
$this
->
synchronizer
->
getCreateSchema
(
$schema
);
$sql
=
$this
->
synchronizer
->
getCreateSchema
(
$schema
);
$this
->
assertEquals
(
array
(
'CREATE TABLE test (id INTEGER NOT NULL, PRIMARY KEY(
"id"
))'
),
$sql
);
$this
->
assertEquals
(
array
(
'CREATE TABLE test (id INTEGER NOT NULL, PRIMARY KEY(
id
))'
),
$sql
);
}
}
public
function
testGetUpdateSchema
()
public
function
testGetUpdateSchema
()
...
@@ -56,7 +56,7 @@ class SingleDatabaseSynchronizerTest extends \PHPUnit_Framework_TestCase
...
@@ -56,7 +56,7 @@ class SingleDatabaseSynchronizerTest extends \PHPUnit_Framework_TestCase
$table
->
setPrimaryKey
(
array
(
'id'
));
$table
->
setPrimaryKey
(
array
(
'id'
));
$sql
=
$this
->
synchronizer
->
getUpdateSchema
(
$schema
);
$sql
=
$this
->
synchronizer
->
getUpdateSchema
(
$schema
);
$this
->
assertEquals
(
array
(
'CREATE TABLE test (id INTEGER NOT NULL, PRIMARY KEY(
"id"
))'
),
$sql
);
$this
->
assertEquals
(
array
(
'CREATE TABLE test (id INTEGER NOT NULL, PRIMARY KEY(
id
))'
),
$sql
);
}
}
public
function
testGetDropSchema
()
public
function
testGetDropSchema
()
...
...
tests/Doctrine/Tests/DBAL/Sharding/PoolingShardManagerTest.php
View file @
b6f48e1a
...
@@ -51,9 +51,10 @@ class PoolingShardManagerTest extends \PHPUnit_Framework_TestCase
...
@@ -51,9 +51,10 @@ class PoolingShardManagerTest extends \PHPUnit_Framework_TestCase
{
{
$shardId
=
10
;
$shardId
=
10
;
$conn
=
$this
->
createConnectionMock
();
$conn
=
$this
->
createConnectionMock
();
$conn
->
expects
(
$this
->
once
())
->
method
(
'connect'
)
->
with
(
$this
->
equalTo
(
$shardId
));
$conn
->
expects
(
$this
->
at
(
0
))
->
method
(
'getParams'
)
->
will
(
$this
->
returnValue
(
array
(
'shardChoser'
=>
$this
->
createPassthroughShardChoser
())));
$conn
->
expects
(
$this
->
at
(
1
))
->
method
(
'connect'
)
->
with
(
$this
->
equalTo
(
$shardId
));
$shardManager
=
new
PoolingShardManager
(
$conn
,
$this
->
createPassthroughShardChoser
()
);
$shardManager
=
new
PoolingShardManager
(
$conn
);
$shardManager
->
selectShard
(
$shardId
);
$shardManager
->
selectShard
(
$shardId
);
$this
->
assertEquals
(
$shardId
,
$shardManager
->
getCurrentDistributionValue
());
$this
->
assertEquals
(
$shardId
,
$shardManager
->
getCurrentDistributionValue
());
...
@@ -62,9 +63,11 @@ class PoolingShardManagerTest extends \PHPUnit_Framework_TestCase
...
@@ -62,9 +63,11 @@ class PoolingShardManagerTest extends \PHPUnit_Framework_TestCase
public
function
testGetShards
()
public
function
testGetShards
()
{
{
$conn
=
$this
->
createConnectionMock
();
$conn
=
$this
->
createConnectionMock
();
$conn
->
expects
(
$this
->
once
())
->
method
(
'getParams'
)
->
will
(
$this
->
returnValue
(
$conn
->
expects
(
$this
->
any
())
->
method
(
'getParams'
)
->
will
(
array
(
'shards'
=>
array
(
array
(
'id'
=>
1
),
array
(
'id'
=>
2
)
))
$this
->
returnValue
(
));
array
(
'shards'
=>
array
(
array
(
'id'
=>
1
),
array
(
'id'
=>
2
)
),
'shardChoser'
=>
$this
->
createPassthroughShardChoser
())
)
);
$shardManager
=
new
PoolingShardManager
(
$conn
,
$this
->
createPassthroughShardChoser
());
$shardManager
=
new
PoolingShardManager
(
$conn
,
$this
->
createPassthroughShardChoser
());
$shards
=
$shardManager
->
getShards
();
$shards
=
$shardManager
->
getShards
();
...
@@ -80,15 +83,18 @@ class PoolingShardManagerTest extends \PHPUnit_Framework_TestCase
...
@@ -80,15 +83,18 @@ class PoolingShardManagerTest extends \PHPUnit_Framework_TestCase
$conn
=
$this
->
createConnectionMock
();
$conn
=
$this
->
createConnectionMock
();
$conn
->
expects
(
$this
->
at
(
0
))
->
method
(
'getParams'
)
->
will
(
$this
->
returnValue
(
$conn
->
expects
(
$this
->
at
(
0
))
->
method
(
'getParams'
)
->
will
(
$this
->
returnValue
(
array
(
'shards'
=>
array
(
array
(
'id'
=>
1
),
array
(
'id'
=>
2
)
))
array
(
'shards'
=>
array
(
array
(
'id'
=>
1
),
array
(
'id'
=>
2
)
),
'shardChoser'
=>
$this
->
createPassthroughShardChoser
())
));
$conn
->
expects
(
$this
->
at
(
1
))
->
method
(
'getParams'
)
->
will
(
$this
->
returnValue
(
array
(
'shards'
=>
array
(
array
(
'id'
=>
1
),
array
(
'id'
=>
2
)
),
'shardChoser'
=>
$this
->
createPassthroughShardChoser
())
));
));
$conn
->
expects
(
$this
->
at
(
1
))
->
method
(
'connect'
)
->
with
(
$this
->
equalTo
(
1
));
$conn
->
expects
(
$this
->
at
(
2
))
->
method
(
'connect'
)
->
with
(
$this
->
equalTo
(
1
));
$conn
->
expects
(
$this
->
at
(
2
))
$conn
->
expects
(
$this
->
at
(
3
))
->
method
(
'fetchAll'
)
->
method
(
'fetchAll'
)
->
with
(
$this
->
equalTo
(
$sql
),
$this
->
equalTo
(
$params
),
$this
->
equalTo
(
$types
))
->
with
(
$this
->
equalTo
(
$sql
),
$this
->
equalTo
(
$params
),
$this
->
equalTo
(
$types
))
->
will
(
$this
->
returnValue
(
array
(
array
(
'id'
=>
1
)
)
));
->
will
(
$this
->
returnValue
(
array
(
array
(
'id'
=>
1
)
)
));
$conn
->
expects
(
$this
->
at
(
3
))
->
method
(
'connect'
)
->
with
(
$this
->
equalTo
(
2
));
$conn
->
expects
(
$this
->
at
(
4
))
->
method
(
'connect'
)
->
with
(
$this
->
equalTo
(
2
));
$conn
->
expects
(
$this
->
at
(
4
))
$conn
->
expects
(
$this
->
at
(
5
))
->
method
(
'fetchAll'
)
->
method
(
'fetchAll'
)
->
with
(
$this
->
equalTo
(
$sql
),
$this
->
equalTo
(
$params
),
$this
->
equalTo
(
$types
))
->
with
(
$this
->
equalTo
(
$sql
),
$this
->
equalTo
(
$params
),
$this
->
equalTo
(
$types
))
->
will
(
$this
->
returnValue
(
array
(
array
(
'id'
=>
2
)
)
));
->
will
(
$this
->
returnValue
(
array
(
array
(
'id'
=>
2
)
)
));
...
...
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