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
4930bf62
Commit
4930bf62
authored
Sep 03, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Validate Database $databaseName and test getters
parent
337075f2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
35 additions
and
0 deletions
+35
-0
Database.php
src/Database.php
+5
-0
DatabaseFunctionalTest.php
tests/Database/DatabaseFunctionalTest.php
+30
-0
No files found.
src/Database.php
View file @
4930bf62
...
@@ -34,9 +34,14 @@ class Database
...
@@ -34,9 +34,14 @@ class Database
* @param string $databaseName Database name
* @param string $databaseName Database name
* @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 $databaseName is invalid
*/
*/
public
function
__construct
(
Manager
$manager
,
$databaseName
,
WriteConcern
$writeConcern
=
null
,
ReadPreference
$readPreference
=
null
)
public
function
__construct
(
Manager
$manager
,
$databaseName
,
WriteConcern
$writeConcern
=
null
,
ReadPreference
$readPreference
=
null
)
{
{
if
(
strlen
(
$databaseName
)
<
1
)
{
throw
new
InvalidArgumentException
(
'$databaseName is invalid: '
.
$databaseName
);
}
$this
->
manager
=
$manager
;
$this
->
manager
=
$manager
;
$this
->
databaseName
=
(
string
)
$databaseName
;
$this
->
databaseName
=
(
string
)
$databaseName
;
$this
->
writeConcern
=
$writeConcern
;
$this
->
writeConcern
=
$writeConcern
;
...
...
tests/Database/DatabaseFunctionalTest.php
View file @
4930bf62
...
@@ -2,11 +2,41 @@
...
@@ -2,11 +2,41 @@
namespace
MongoDB\Tests\Database
;
namespace
MongoDB\Tests\Database
;
use
MongoDB\Database
;
/**
/**
* Functional tests for the Database class.
* Functional tests for the Database class.
*/
*/
class
DatabaseFunctionalTest
extends
FunctionalTestCase
class
DatabaseFunctionalTest
extends
FunctionalTestCase
{
{
/**
* @expectedException MongoDB\Exception\InvalidArgumentException
* @dataProvider provideInvalidDatabaseValues
*/
public
function
testConstructorDatabaseNameArgument
(
$databaseName
)
{
// TODO: Move to unit test once ManagerInterface can be mocked (PHPC-378)
new
Database
(
$this
->
manager
,
$databaseName
);
}
public
function
provideInvalidDatabaseValues
()
{
return
array
(
array
(
null
),
array
(
''
),
);
}
public
function
testToString
()
{
$this
->
assertEquals
(
$this
->
getDatabaseName
(),
(
string
)
$this
->
database
);
}
public
function
getGetDatabaseName
()
{
$this
->
assertEquals
(
$this
->
getDatabaseName
(),
$this
->
database
->
getDatabaseName
());
}
public
function
testDrop
()
public
function
testDrop
()
{
{
$writeResult
=
$this
->
manager
->
executeInsert
(
$this
->
getNamespace
(),
array
(
'x'
=>
1
));
$writeResult
=
$this
->
manager
->
executeInsert
(
$this
->
getNamespace
(),
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