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
337075f2
Commit
337075f2
authored
Sep 03, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validate Collection $namespace and test getters
parent
303a09ea
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
52 additions
and
2 deletions
+52
-2
Collection.php
src/Collection.php
+10
-2
CollectionFunctionalTest.php
tests/Collection/CollectionFunctionalTest.php
+42
-0
No files found.
src/Collection.php
View file @
337075f2
...
@@ -52,14 +52,22 @@ class Collection
...
@@ -52,14 +52,22 @@ class Collection
* @param string $namespace Collection namespace (e.g. "db.collection")
* @param string $namespace Collection namespace (e.g. "db.collection")
* @param WriteConcern $writeConcern Default write concern to apply
* @param WriteConcern $writeConcern Default write concern to apply
* @param ReadPreference $readPreference Default read preference to apply
* @param ReadPreference $readPreference Default read preference to apply
* @throws InvalidArgumentException if $namespace is invalid
*/
*/
public
function
__construct
(
Manager
$manager
,
$namespace
,
WriteConcern
$writeConcern
=
null
,
ReadPreference
$readPreference
=
null
)
public
function
__construct
(
Manager
$manager
,
$namespace
,
WriteConcern
$writeConcern
=
null
,
ReadPreference
$readPreference
=
null
)
{
{
$parts
=
explode
(
'.'
,
$namespace
,
2
);
if
(
count
(
$parts
)
!=
2
||
strlen
(
$parts
[
0
])
==
0
||
strlen
(
$parts
[
1
])
==
0
)
{
throw
new
InvalidArgumentException
(
'$namespace is invalid: '
.
$namespace
);
}
$this
->
databaseName
=
$parts
[
0
];
$this
->
collectionName
=
$parts
[
1
];
$this
->
manager
=
$manager
;
$this
->
manager
=
$manager
;
$this
->
writeConcern
=
$writeConcern
;
$this
->
writeConcern
=
$writeConcern
;
$this
->
readPreference
=
$readPreference
;
$this
->
readPreference
=
$readPreference
;
list
(
$this
->
databaseName
,
$this
->
collectionName
)
=
explode
(
"."
,
$namespace
,
2
);
}
}
/**
/**
...
...
tests/Collection/CollectionFunctionalTest.php
View file @
337075f2
...
@@ -2,6 +2,7 @@
...
@@ -2,6 +2,7 @@
namespace
MongoDB\Tests\Collection
;
namespace
MongoDB\Tests\Collection
;
use
MongoDB\Collection
;
use
MongoDB\Driver\BulkWrite
;
use
MongoDB\Driver\BulkWrite
;
/**
/**
...
@@ -9,6 +10,47 @@ use MongoDB\Driver\BulkWrite;
...
@@ -9,6 +10,47 @@ use MongoDB\Driver\BulkWrite;
*/
*/
class
CollectionFunctionalTest
extends
FunctionalTestCase
class
CollectionFunctionalTest
extends
FunctionalTestCase
{
{
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidNamespaceValues
*/
public
function
testConstructorNamespaceArgument
(
$namespace
)
{
// TODO: Move to unit test once ManagerInterface can be mocked (PHPC-378)
new
Collection
(
$this
->
manager
,
$namespace
);
}
public
function
provideInvalidNamespaceValues
()
{
return
array
(
array
(
null
),
array
(
''
),
array
(
'db_collection'
),
array
(
'db'
),
array
(
'.collection'
),
);
}
public
function
testToString
()
{
$this
->
assertEquals
(
$this
->
getNamespace
(),
(
string
)
$this
->
collection
);
}
public
function
getGetCollectionName
()
{
$this
->
assertEquals
(
$this
->
getCollectionName
(),
$this
->
collection
->
getCollectionName
());
}
public
function
getGetDatabaseName
()
{
$this
->
assertEquals
(
$this
->
getDatabaseName
(),
$this
->
collection
->
getDatabaseName
());
}
public
function
testGetNamespace
()
{
$this
->
assertEquals
(
$this
->
getNamespace
(),
$this
->
collection
->
getNamespace
());
}
public
function
testDrop
()
public
function
testDrop
()
{
{
$writeResult
=
$this
->
collection
->
insertOne
(
array
(
'x'
=>
1
));
$writeResult
=
$this
->
collection
->
insertOne
(
array
(
'x'
=>
1
));
...
...
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