Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
Project
Project
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
sinan
mongo-php-library
Commits
af9bc65d
Commit
af9bc65d
authored
Jan 19, 2016
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #97
parents
7039bd7a
c56c7e2b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
61 additions
and
0 deletions
+61
-0
Client.php
src/Client.php
+17
-0
Database.php
src/Database.php
+17
-0
ClientTest.php
tests/ClientTest.php
+13
-0
DatabaseFunctionalTest.php
tests/Database/DatabaseFunctionalTest.php
+14
-0
No files found.
src/Client.php
View file @
af9bc65d
...
...
@@ -73,6 +73,23 @@ class Client
];
}
/**
* Select a database.
*
* Note: collections whose names contain special characters (e.g. "-") may
* be selected with complex syntax (e.g. $client->{"that-database"}) or
* {@link selectDatabase()}.
*
* @see http://php.net/oop5.overloading#object.get
* @see http://php.net/types.string#language.types.string.parsing.complex
* @param string $databaseName Name of the database to select
* @return Database
*/
public
function
__get
(
$databaseName
)
{
return
$this
->
selectDatabase
(
$databaseName
);
}
/**
* Return the connection string (i.e. URI).
*
...
...
src/Database.php
View file @
af9bc65d
...
...
@@ -102,6 +102,23 @@ class Database
];
}
/**
* Select a collection within this database.
*
* Note: collections whose names contain special characters (e.g. ".") may
* be selected with complex syntax (e.g. $database->{"system.profile"}) or
* {@link selectCollection()}.
*
* @see http://php.net/oop5.overloading#object.get
* @see http://php.net/types.string#language.types.string.parsing.complex
* @param string $collectionName Name of the collection to select
* @return Collection
*/
public
function
__get
(
$collectionName
)
{
return
$this
->
selectCollection
(
$collectionName
);
}
/**
* Return the database name.
*
...
...
tests/ClientTest.php
View file @
af9bc65d
...
...
@@ -97,6 +97,19 @@ class ClientTest extends TestCase
$this
->
assertSame
(
WriteConcern
::
MAJORITY
,
$debug
[
'writeConcern'
]
->
getW
());
}
public
function
testGetSelectsDatabaseAndInheritsOptions
()
{
$uriOptions
=
[
'w'
=>
WriteConcern
::
MAJORITY
];
$client
=
new
Client
(
$this
->
getUri
(),
$uriOptions
);
$database
=
$client
->
{
$this
->
getDatabaseName
()};
$debug
=
$database
->
__debugInfo
();
$this
->
assertSame
(
$this
->
getDatabaseName
(),
$debug
[
'databaseName'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
$this
->
assertSame
(
WriteConcern
::
MAJORITY
,
$debug
[
'writeConcern'
]
->
getW
());
}
public
function
testSelectDatabaseInheritsOptions
()
{
$this
->
markTestSkipped
(
'Depends on https://jira.mongodb.org/browse/PHPC-523'
);
...
...
tests/Database/DatabaseFunctionalTest.php
View file @
af9bc65d
...
...
@@ -131,6 +131,20 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$this
->
assertCollectionCount
(
$this
->
getNamespace
(),
0
);
}
public
function
testGetSelectsCollectionAndInheritsOptions
()
{
$databaseOptions
=
[
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
)];
$database
=
new
Database
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$databaseOptions
);
$collection
=
$database
->
{
$this
->
getCollectionName
()};
$debug
=
$collection
->
__debugInfo
();
$this
->
assertSame
(
$this
->
getCollectionName
(),
$debug
[
'collectionName'
]);
$this
->
assertSame
(
$this
->
getDatabaseName
(),
$debug
[
'databaseName'
]);
$this
->
assertInstanceOf
(
'MongoDB\Driver\WriteConcern'
,
$debug
[
'writeConcern'
]);
$this
->
assertSame
(
WriteConcern
::
MAJORITY
,
$debug
[
'writeConcern'
]
->
getW
());
}
public
function
testSelectCollectionInheritsOptions
()
{
$databaseOptions
=
[
...
...
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