Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
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
PSDI Army
yii2
Commits
3abefac6
Commit
3abefac6
authored
Oct 07, 2014
by
Klimov Paul
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed `yii\mongodb\Collection` unable to fetch default database name from DSN with parameters
parent
b9520596
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
40 additions
and
2 deletions
+40
-2
CHANGELOG.md
extensions/mongodb/CHANGELOG.md
+1
-1
Connection.php
extensions/mongodb/Connection.php
+1
-1
ConnectionTest.php
tests/unit/extensions/mongodb/ConnectionTest.php
+38
-0
No files found.
extensions/mongodb/CHANGELOG.md
View file @
3abefac6
...
...
@@ -4,7 +4,7 @@ Yii Framework 2 mongodb extension Change Log
2.
0.0 under development
-----------------------
-
no changes in this release.
-
Bug #5303: Fixed
`yii\mongodb\Collection`
unable to fetch default database name from DSN with parameters (klimov-paul)
2.0.0-rc September 27, 2014
...
...
extensions/mongodb/Connection.php
View file @
3abefac6
...
...
@@ -148,7 +148,7 @@ class Connection extends Component
if
(
$this
->
defaultDatabaseName
===
null
)
{
if
(
isset
(
$this
->
options
[
'db'
]))
{
$this
->
defaultDatabaseName
=
$this
->
options
[
'db'
];
}
elseif
(
preg_match
(
'/^mongodb:\\/\\/.+\\/(
.+)$
/s'
,
$this
->
dsn
,
$matches
))
{
}
elseif
(
preg_match
(
'/^mongodb:\\/\\/.+\\/(
[^?&]+)
/s'
,
$this
->
dsn
,
$matches
))
{
$this
->
defaultDatabaseName
=
$matches
[
1
];
}
else
{
throw
new
InvalidConfigException
(
"Unable to determine default database name from dsn."
);
...
...
tests/unit/extensions/mongodb/ConnectionTest.php
View file @
3abefac6
...
...
@@ -61,7 +61,45 @@ class ConnectionTest extends MongoDbTestCase
}
/**
* Data provider for [[testFetchDefaultDatabaseName()]]
* @return array test data
*/
public
function
dataProviderFetchDefaultDatabaseName
()
{
return
[
[
'mongodb://travis:test@localhost:27017/dbname'
,
'dbname'
,
],
[
'mongodb://travis:test@localhost:27017/dbname?replicaSet=test&connectTimeoutMS=300000'
,
'dbname'
,
],
];
}
/**
* @dataProvider dataProviderFetchDefaultDatabaseName
*
* @param string $dsn
* @param string $databaseName
*/
public
function
testFetchDefaultDatabaseName
(
$dsn
,
$databaseName
)
{
$connection
=
new
Connection
();
$connection
->
dsn
=
$dsn
;
$reflection
=
new
\ReflectionObject
(
$connection
);
$method
=
$reflection
->
getMethod
(
'fetchDefaultDatabaseName'
);
$method
->
setAccessible
(
true
);
$method
->
invoke
(
$connection
);
$this
->
assertEquals
(
$databaseName
,
$connection
->
defaultDatabaseName
);
}
/**
* @depends testGetDatabase
* @depends testFetchDefaultDatabaseName
*/
public
function
testGetDefaultDatabase
()
{
...
...
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