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
9d087e5a
Commit
9d087e5a
authored
Dec 16, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #48
parents
a4992db2
0cd9709a
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
130 additions
and
40 deletions
+130
-40
Database.php
src/Database.php
+26
-0
DatabaseFunctionalTest.php
tests/Database/DatabaseFunctionalTest.php
+23
-0
BulkWriteTest.php
tests/Operation/BulkWriteTest.php
+5
-0
TestCase.php
tests/Operation/TestCase.php
+0
-40
TestCase.php
tests/TestCase.php
+76
-0
No files found.
src/Database.php
View file @
9d087e5a
...
@@ -92,6 +92,32 @@ class Database
...
@@ -92,6 +92,32 @@ class Database
return
$this
->
databaseName
;
return
$this
->
databaseName
;
}
}
/**
* Execute a command on this database.
*
* @param array|object $command Command document
* @param ReadPreference|null $readPreference Read preference
* @return Cursor
*/
public
function
command
(
$command
,
ReadPreference
$readPreference
=
null
)
{
if
(
!
is_array
(
$command
)
&&
!
is_object
(
$command
))
{
throw
new
InvalidArgumentTypeException
(
'$command'
,
$command
,
'array or object'
);
}
if
(
!
$command
instanceof
Command
)
{
$command
=
new
Command
(
$command
);
}
if
(
!
isset
(
$readPreference
))
{
$readPreference
=
$this
->
readPreference
;
}
$server
=
$this
->
manager
->
selectServer
(
$readPreference
);
return
$server
->
executeCommand
(
$this
->
databaseName
,
$command
);
}
/**
/**
* Create a new collection explicitly.
* Create a new collection explicitly.
*
*
...
...
tests/Database/DatabaseFunctionalTest.php
View file @
9d087e5a
...
@@ -64,6 +64,29 @@ class DatabaseFunctionalTest extends FunctionalTestCase
...
@@ -64,6 +64,29 @@ class DatabaseFunctionalTest extends FunctionalTestCase
$this
->
assertEquals
(
$this
->
getDatabaseName
(),
$this
->
database
->
getDatabaseName
());
$this
->
assertEquals
(
$this
->
getDatabaseName
(),
$this
->
database
->
getDatabaseName
());
}
}
public
function
testCommand
()
{
$command
=
[
'isMaster'
=>
1
];
$readPreference
=
new
ReadPreference
(
ReadPreference
::
RP_PRIMARY
);
$cursor
=
$this
->
database
->
command
(
$command
,
$readPreference
);
$this
->
assertInstanceOf
(
'MongoDB\Driver\Cursor'
,
$cursor
);
$commandResult
=
current
(
$cursor
->
toArray
());
$this
->
assertCommandSucceeded
(
$commandResult
);
$this
->
assertTrue
(
isset
(
$commandResult
->
ismaster
));
$this
->
assertTrue
(
$commandResult
->
ismaster
);
}
/**
* @expectedException MongoDB\Exception\InvalidArgumentTypeException
* @dataProvider provideInvalidDocumentValues
*/
public
function
testCommandCommandArgumentTypeCheck
(
$command
)
{
$this
->
database
->
command
(
$command
);
}
public
function
testDrop
()
public
function
testDrop
()
{
{
$bulkWrite
=
new
BulkWrite
();
$bulkWrite
=
new
BulkWrite
();
...
...
tests/Operation/BulkWriteTest.php
View file @
9d087e5a
...
@@ -341,6 +341,11 @@ class BulkWriteTest extends TestCase
...
@@ -341,6 +341,11 @@ class BulkWriteTest extends TestCase
);
);
}
}
public
function
provideInvalidBooleanValues
()
{
return
$this
->
wrapValuesForDataProvider
(
$this
->
getInvalidBooleanValues
());
}
public
function
provideInvalidConstructorOptions
()
public
function
provideInvalidConstructorOptions
()
{
{
$options
=
[];
$options
=
[];
...
...
tests/Operation/TestCase.php
View file @
9d087e5a
...
@@ -3,50 +3,10 @@
...
@@ -3,50 +3,10 @@
namespace
MongoDB\Tests\Operation
;
namespace
MongoDB\Tests\Operation
;
use
MongoDB\Tests\TestCase
as
BaseTestCase
;
use
MongoDB\Tests\TestCase
as
BaseTestCase
;
use
stdClass
;
/**
/**
* Base class for Operation unit tests.
* Base class for Operation unit tests.
*/
*/
abstract
class
TestCase
extends
BaseTestCase
abstract
class
TestCase
extends
BaseTestCase
{
{
public
function
provideInvalidDocumentValues
()
{
return
$this
->
wrapValuesForDataProvider
(
$this
->
getInvalidDocumentValues
());
}
public
function
provideInvalidBooleanValues
()
{
return
$this
->
wrapValuesForDataProvider
(
$this
->
getInvalidBooleanValues
());
}
protected
function
getInvalidArrayValues
()
{
return
[
123
,
3.14
,
'foo'
,
true
,
new
stdClass
];
}
protected
function
getInvalidBooleanValues
()
{
return
[
123
,
3.14
,
'foo'
,
[],
new
stdClass
];
}
protected
function
getInvalidDocumentValues
()
{
return
[
123
,
3.14
,
'foo'
,
true
];
}
protected
function
getInvalidIntegerValues
()
{
return
[
3.14
,
'foo'
,
true
,
[],
new
stdClass
];
}
protected
function
getInvalidStringValues
()
{
return
[
123
,
3.14
,
true
,
[],
new
stdClass
];
}
protected
function
wrapValuesForDataProvider
(
array
$values
)
{
return
array_map
(
function
(
$value
)
{
return
[
$value
];
},
$values
);
}
}
}
tests/TestCase.php
View file @
9d087e5a
...
@@ -7,6 +7,11 @@ use stdClass;
...
@@ -7,6 +7,11 @@ use stdClass;
abstract
class
TestCase
extends
\PHPUnit_Framework_TestCase
abstract
class
TestCase
extends
\PHPUnit_Framework_TestCase
{
{
public
function
provideInvalidDocumentValues
()
{
return
$this
->
wrapValuesForDataProvider
(
$this
->
getInvalidDocumentValues
());
}
/**
/**
* Return the test collection name.
* Return the test collection name.
*
*
...
@@ -29,11 +34,71 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
...
@@ -29,11 +34,71 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
return
getenv
(
'MONGODB_DATABASE'
)
?:
'phplib_test'
;
return
getenv
(
'MONGODB_DATABASE'
)
?:
'phplib_test'
;
}
}
/**
* Return a list of invalid array values.
*
* @return array
*/
protected
function
getInvalidArrayValues
()
{
return
[
123
,
3.14
,
'foo'
,
true
,
new
stdClass
];
}
/**
* Return a list of invalid boolean values.
*
* @return array
*/
protected
function
getInvalidBooleanValues
()
{
return
[
123
,
3.14
,
'foo'
,
[],
new
stdClass
];
}
/**
* Return a list of invalid document values.
*
* @return array
*/
protected
function
getInvalidDocumentValues
()
{
return
[
123
,
3.14
,
'foo'
,
true
];
}
/**
* Return a list of invalid integer values.
*
* @return array
*/
protected
function
getInvalidIntegerValues
()
{
return
[
3.14
,
'foo'
,
true
,
[],
new
stdClass
];
}
/**
* Return a list of invalid ReadPreference values.
*
* @return array
*/
protected
function
getInvalidReadPreferenceValues
()
protected
function
getInvalidReadPreferenceValues
()
{
{
return
[
123
,
3.14
,
'foo'
,
true
,
[],
new
stdClass
];
return
[
123
,
3.14
,
'foo'
,
true
,
[],
new
stdClass
];
}
}
/**
* Return a list of invalid string values.
*
* @return array
*/
protected
function
getInvalidStringValues
()
{
return
[
123
,
3.14
,
true
,
[],
new
stdClass
];
}
/**
* Return a list of invalid WriteConcern values.
*
* @return array
*/
protected
function
getInvalidWriteConcernValues
()
protected
function
getInvalidWriteConcernValues
()
{
{
return
[
123
,
3.14
,
'foo'
,
true
,
[],
new
stdClass
];
return
[
123
,
3.14
,
'foo'
,
true
,
[],
new
stdClass
];
...
@@ -58,4 +123,15 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
...
@@ -58,4 +123,15 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
{
{
return
getenv
(
'MONGODB_URI'
)
?:
'mongodb://127.0.0.1:27017'
;
return
getenv
(
'MONGODB_URI'
)
?:
'mongodb://127.0.0.1:27017'
;
}
}
/**
* Wrap a list of values for use as a single-argument data provider.
*
* @param array $values List of values
* @return array
*/
protected
function
wrapValuesForDataProvider
(
array
$values
)
{
return
array_map
(
function
(
$value
)
{
return
[
$value
];
},
$values
);
}
}
}
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