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
2152f0ef
Commit
2152f0ef
authored
Jan 20, 2016
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-165: Take explicit db/coll name args in Collection ctor
parent
5a44dc72
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
36 additions
and
26 deletions
+36
-26
Client.php
src/Client.php
+1
-1
Collection.php
src/Collection.php
+14
-11
Database.php
src/Database.php
+1
-1
CollectionFunctionalTest.php
tests/Collection/CollectionFunctionalTest.php
+16
-9
AggregateFunctionalTest.php
tests/Collection/CrudSpec/AggregateFunctionalTest.php
+1
-1
FunctionalTestCase.php
tests/Collection/FunctionalTestCase.php
+1
-1
DatabaseFunctionalTest.php
tests/Database/DatabaseFunctionalTest.php
+2
-2
No files found.
src/Client.php
View file @
2152f0ef
...
@@ -147,7 +147,7 @@ class Client
...
@@ -147,7 +147,7 @@ class Client
{
{
$options
+=
[
'typeMap'
=>
$this
->
typeMap
];
$options
+=
[
'typeMap'
=>
$this
->
typeMap
];
return
new
Collection
(
$this
->
manager
,
$databaseName
.
'.'
.
$collectionName
,
$options
);
return
new
Collection
(
$this
->
manager
,
$databaseName
,
$collectionName
,
$options
);
}
}
/**
/**
...
...
src/Collection.php
View file @
2152f0ef
...
@@ -73,20 +73,20 @@ class Collection
...
@@ -73,20 +73,20 @@ class Collection
* concern.
* concern.
*
*
* @param Manager $manager Manager instance from the driver
* @param Manager $manager Manager instance from the driver
* @param string $namespace Collection namespace (e.g. "db.collection")
* @param string $databaseName Database name
* @param string $collectionName Collection name
* @param array $options Collection options
* @param array $options Collection options
* @throws InvalidArgumentException
* @throws InvalidArgumentException
*/
*/
public
function
__construct
(
Manager
$manager
,
$
namespac
e
,
array
$options
=
[])
public
function
__construct
(
Manager
$manager
,
$
databaseName
,
$collectionNam
e
,
array
$options
=
[])
{
{
$parts
=
explode
(
'.'
,
$namespace
,
2
);
if
(
strlen
(
$databaseName
)
<
1
)
{
throw
new
InvalidArgumentException
(
'$databaseName is invalid: '
.
$databaseName
);
if
(
count
(
$parts
)
!=
2
||
strlen
(
$parts
[
0
])
==
0
||
strlen
(
$parts
[
1
])
==
0
)
{
throw
new
InvalidArgumentException
(
'$namespace is invalid: '
.
$namespace
);
}
}
$this
->
databaseName
=
$parts
[
0
];
if
(
strlen
(
$collectionName
)
<
1
)
{
$this
->
collectionName
=
$parts
[
1
];
throw
new
InvalidArgumentException
(
'$collectionName is invalid: '
.
$collectionName
);
}
if
(
isset
(
$options
[
'readConcern'
])
&&
!
$options
[
'readConcern'
]
instanceof
ReadConcern
)
{
if
(
isset
(
$options
[
'readConcern'
])
&&
!
$options
[
'readConcern'
]
instanceof
ReadConcern
)
{
throw
InvalidArgumentException
::
invalidType
(
'"readConcern" option'
,
$options
[
'readConcern'
],
'MongoDB\Driver\ReadConcern'
);
throw
InvalidArgumentException
::
invalidType
(
'"readConcern" option'
,
$options
[
'readConcern'
],
'MongoDB\Driver\ReadConcern'
);
...
@@ -105,6 +105,8 @@ class Collection
...
@@ -105,6 +105,8 @@ class Collection
}
}
$this
->
manager
=
$manager
;
$this
->
manager
=
$manager
;
$this
->
databaseName
=
(
string
)
$databaseName
;
$this
->
collectionName
=
(
string
)
$collectionName
;
$this
->
readConcern
=
isset
(
$options
[
'readConcern'
])
?
$options
[
'readConcern'
]
:
$this
->
manager
->
getReadConcern
();
$this
->
readConcern
=
isset
(
$options
[
'readConcern'
])
?
$options
[
'readConcern'
]
:
$this
->
manager
->
getReadConcern
();
$this
->
readPreference
=
isset
(
$options
[
'readPreference'
])
?
$options
[
'readPreference'
]
:
$this
->
manager
->
getReadPreference
();
$this
->
readPreference
=
isset
(
$options
[
'readPreference'
])
?
$options
[
'readPreference'
]
:
$this
->
manager
->
getReadPreference
();
$this
->
typeMap
=
isset
(
$options
[
'typeMap'
])
?
$options
[
'typeMap'
]
:
self
::
$defaultTypeMap
;
$this
->
typeMap
=
isset
(
$options
[
'typeMap'
])
?
$options
[
'typeMap'
]
:
self
::
$defaultTypeMap
;
...
@@ -133,6 +135,7 @@ class Collection
...
@@ -133,6 +135,7 @@ class Collection
/**
/**
* Return the collection namespace (e.g. "db.collection").
* Return the collection namespace (e.g. "db.collection").
*
*
* @see https://docs.mongodb.org/manual/faq/developers/#faq-dev-namespace
* @param string
* @param string
*/
*/
public
function
__toString
()
public
function
__toString
()
...
@@ -723,6 +726,6 @@ class Collection
...
@@ -723,6 +726,6 @@ class Collection
'writeConcern'
=>
$this
->
writeConcern
,
'writeConcern'
=>
$this
->
writeConcern
,
];
];
return
new
Collection
(
$this
->
manager
,
$this
->
databaseName
.
'.'
.
$this
->
collectionName
,
$options
);
return
new
Collection
(
$this
->
manager
,
$this
->
databaseName
,
$this
->
collectionName
,
$options
);
}
}
}
}
src/Database.php
View file @
2152f0ef
...
@@ -257,7 +257,7 @@ class Database
...
@@ -257,7 +257,7 @@ class Database
'writeConcern'
=>
$this
->
writeConcern
,
'writeConcern'
=>
$this
->
writeConcern
,
];
];
return
new
Collection
(
$this
->
manager
,
$this
->
databaseName
.
'.'
.
$collectionName
,
$options
);
return
new
Collection
(
$this
->
manager
,
$this
->
databaseName
,
$collectionName
,
$options
);
}
}
/**
/**
...
...
tests/Collection/CollectionFunctionalTest.php
View file @
2152f0ef
...
@@ -15,22 +15,29 @@ class CollectionFunctionalTest extends FunctionalTestCase
...
@@ -15,22 +15,29 @@ class CollectionFunctionalTest extends FunctionalTestCase
{
{
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalid
NamespaceValu
es
* @dataProvider provideInvalid
DatabaseAndCollectionNam
es
*/
*/
public
function
testConstructor
NamespaceArgument
(
$namespac
e
)
public
function
testConstructor
DatabaseNameArgument
(
$databaseNam
e
)
{
{
// TODO: Move to unit test once ManagerInterface can be mocked (PHPC-378)
// TODO: Move to unit test once ManagerInterface can be mocked (PHPC-378)
new
Collection
(
$this
->
manager
,
$
namespace
);
new
Collection
(
$this
->
manager
,
$
databaseName
,
$this
->
getCollectionName
()
);
}
}
public
function
provideInvalidNamespaceValues
()
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDatabaseAndCollectionNames
*/
public
function
testConstructorCollectionNameArgument
(
$collectionName
)
{
// TODO: Move to unit test once ManagerInterface can be mocked (PHPC-378)
new
Collection
(
$this
->
manager
,
$this
->
getDatabaseName
(),
$collectionName
);
}
public
function
provideInvalidDatabaseAndCollectionNames
()
{
{
return
[
return
[
[
null
],
[
null
],
[
''
],
[
''
],
[
'db_collection'
],
[
'db'
],
[
'.collection'
],
];
];
}
}
...
@@ -40,7 +47,7 @@ class CollectionFunctionalTest extends FunctionalTestCase
...
@@ -40,7 +47,7 @@ class CollectionFunctionalTest extends FunctionalTestCase
*/
*/
public
function
testConstructorOptionTypeChecks
(
array
$options
)
public
function
testConstructorOptionTypeChecks
(
array
$options
)
{
{
new
Collection
(
$this
->
manager
,
$this
->
get
Namespac
e
(),
$options
);
new
Collection
(
$this
->
manager
,
$this
->
get
DatabaseName
(),
$this
->
getCollectionNam
e
(),
$options
);
}
}
public
function
provideInvalidConstructorOptions
()
public
function
provideInvalidConstructorOptions
()
...
@@ -129,7 +136,7 @@ class CollectionFunctionalTest extends FunctionalTestCase
...
@@ -129,7 +136,7 @@ class CollectionFunctionalTest extends FunctionalTestCase
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
'writeConcern'
=>
new
WriteConcern
(
WriteConcern
::
MAJORITY
),
];
];
$collection
=
new
Collection
(
$this
->
manager
,
$this
->
get
Namespac
e
(),
$collectionOptions
);
$collection
=
new
Collection
(
$this
->
manager
,
$this
->
get
DatabaseName
(),
$this
->
getCollectionNam
e
(),
$collectionOptions
);
$clone
=
$collection
->
withOptions
();
$clone
=
$collection
->
withOptions
();
$debug
=
$clone
->
__debugInfo
();
$debug
=
$clone
->
__debugInfo
();
...
...
tests/Collection/CrudSpec/AggregateFunctionalTest.php
View file @
2152f0ef
...
@@ -48,7 +48,7 @@ class AggregateFunctionalTest extends FunctionalTestCase
...
@@ -48,7 +48,7 @@ class AggregateFunctionalTest extends FunctionalTestCase
$this
->
markTestSkipped
(
'$out aggregation pipeline operator is not supported'
);
$this
->
markTestSkipped
(
'$out aggregation pipeline operator is not supported'
);
}
}
$outputCollection
=
new
Collection
(
$this
->
manager
,
$this
->
get
Namespac
e
()
.
'_output'
);
$outputCollection
=
new
Collection
(
$this
->
manager
,
$this
->
get
DatabaseName
(),
$this
->
getCollectionNam
e
()
.
'_output'
);
$operation
=
new
DropCollection
(
$this
->
getDatabaseName
(),
$outputCollection
->
getCollectionName
());
$operation
=
new
DropCollection
(
$this
->
getDatabaseName
(),
$outputCollection
->
getCollectionName
());
$operation
->
execute
(
$this
->
getPrimaryServer
());
$operation
->
execute
(
$this
->
getPrimaryServer
());
...
...
tests/Collection/FunctionalTestCase.php
View file @
2152f0ef
...
@@ -17,7 +17,7 @@ abstract class FunctionalTestCase extends BaseFunctionalTestCase
...
@@ -17,7 +17,7 @@ abstract class FunctionalTestCase extends BaseFunctionalTestCase
{
{
parent
::
setUp
();
parent
::
setUp
();
$this
->
collection
=
new
Collection
(
$this
->
manager
,
$this
->
get
Namespac
e
());
$this
->
collection
=
new
Collection
(
$this
->
manager
,
$this
->
get
DatabaseName
(),
$this
->
getCollectionNam
e
());
$operation
=
new
DropCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
$operation
=
new
DropCollection
(
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
$operation
->
execute
(
$this
->
getPrimaryServer
());
$operation
->
execute
(
$this
->
getPrimaryServer
());
}
}
...
...
tests/Database/DatabaseFunctionalTest.php
View file @
2152f0ef
...
@@ -15,7 +15,7 @@ class DatabaseFunctionalTest extends FunctionalTestCase
...
@@ -15,7 +15,7 @@ class DatabaseFunctionalTest extends FunctionalTestCase
{
{
/**
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDatabase
Valu
es
* @dataProvider provideInvalidDatabase
Nam
es
*/
*/
public
function
testConstructorDatabaseNameArgument
(
$databaseName
)
public
function
testConstructorDatabaseNameArgument
(
$databaseName
)
{
{
...
@@ -23,7 +23,7 @@ class DatabaseFunctionalTest extends FunctionalTestCase
...
@@ -23,7 +23,7 @@ class DatabaseFunctionalTest extends FunctionalTestCase
new
Database
(
$this
->
manager
,
$databaseName
);
new
Database
(
$this
->
manager
,
$databaseName
);
}
}
public
function
provideInvalidDatabase
Valu
es
()
public
function
provideInvalidDatabase
Nam
es
()
{
{
return
[
return
[
[
null
],
[
null
],
...
...
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