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
c520df8a
Commit
c520df8a
authored
Apr 27, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Split Database and Collection functional tests
parent
f3492fb1
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
146 additions
and
85 deletions
+146
-85
CollectionFunctionalTest.php
tests/Collection/CollectionFunctionalTest.php
+51
-0
FunctionalTestCase.php
tests/Collection/FunctionalTestCase.php
+38
-0
IndexManagementFunctionalTest.php
tests/Collection/IndexManagementFunctionalTest.php
+7
-54
CollectionManagementFunctionalTest.php
tests/Database/CollectionManagementFunctionalTest.php
+3
-25
DatabaseFunctionalTest.php
tests/Database/DatabaseFunctionalTest.php
+19
-0
FunctionalTestCase.php
tests/Database/FunctionalTestCase.php
+22
-0
FunctionalTestCase.php
tests/FunctionalTestCase.php
+2
-2
TestCase.php
tests/TestCase.php
+4
-4
No files found.
tests/Collection/CollectionFunctionalTest.php
0 → 100644
View file @
c520df8a
<?php
namespace
MongoDB\Tests\Collection
;
use
MongoDB\Tests\FixtureGenerator
;
/**
* Functional tests for the Collection class.
*/
class
CollectionFunctionalTest
extends
FunctionalTestCase
{
public
function
testDrop
()
{
$writeResult
=
$this
->
collection
->
insertOne
(
array
(
'x'
=>
1
));
$this
->
assertEquals
(
1
,
$writeResult
->
getInsertedCount
());
$commandResult
=
$this
->
collection
->
drop
();
$this
->
assertCommandSucceeded
(
$commandResult
);
$this
->
assertCollectionCount
(
$this
->
getNamespace
(),
0
);
}
function
testInsertAndRetrieve
()
{
$generator
=
new
FixtureGenerator
();
for
(
$i
=
0
;
$i
<
10
;
$i
++
)
{
$user
=
$generator
->
createUser
();
$result
=
$this
->
collection
->
insertOne
(
$user
);
$this
->
assertInstanceOf
(
'MongoDB\InsertOneResult'
,
$result
);
$this
->
assertInstanceOf
(
'BSON\ObjectId'
,
$result
->
getInsertedId
());
$this
->
assertEquals
(
24
,
strlen
(
$result
->
getInsertedId
()));
$user
[
"_id"
]
=
$result
->
getInsertedId
();
$document
=
$this
->
collection
->
findOne
(
array
(
"_id"
=>
$result
->
getInsertedId
()));
$this
->
assertEquals
(
$document
,
$user
,
"The inserted and returned objects are the same"
);
}
$this
->
assertEquals
(
10
,
$i
);
$query
=
array
(
"firstName"
=>
"Ransom"
);
$count
=
$this
->
collection
->
count
(
$query
);
$this
->
assertEquals
(
1
,
$count
);
$cursor
=
$this
->
collection
->
find
(
$query
);
$this
->
assertInstanceOf
(
'MongoDB\Driver\Cursor'
,
$cursor
);
foreach
(
$cursor
as
$n
=>
$person
)
{
$this
->
assertInternalType
(
"array"
,
$person
);
}
$this
->
assertEquals
(
0
,
$n
);
}
}
tests/Collection/FunctionalTestCase.php
0 → 100644
View file @
c520df8a
<?php
namespace
MongoDB\Tests\Collection
;
use
MongoDB\Collection
;
use
MongoDB\Database
;
use
MongoDB\Tests\FunctionalTestCase
as
BaseFunctionalTestCase
;
/**
* Base class for Collection functional tests.
*/
abstract
class
FunctionalTestCase
extends
BaseFunctionalTestCase
{
protected
$collection
;
public
function
setUp
()
{
parent
::
setUp
();
$this
->
collection
=
new
Collection
(
$this
->
manager
,
$this
->
getNamespace
());
$this
->
dropCollectionIfItExists
(
$this
->
collection
);
}
/**
* Drop the collection if it exists.
*
* @param Collection $collection
*/
protected
function
dropCollectionIfItExists
(
Collection
$collection
)
{
$database
=
new
Database
(
$this
->
manager
,
$collection
->
getDatabaseName
());
$collections
=
$database
->
listCollections
(
array
(
'filter'
=>
array
(
'name'
=>
$collection
->
getCollectionName
())));
if
(
iterator_count
(
$collections
)
>
0
)
{
$this
->
assertCommandSucceeded
(
$collection
->
drop
());
}
}
}
tests/CollectionFunctionalTest.php
→
tests/Collection
/IndexManagement
FunctionalTest.php
View file @
c520df8a
<?php
<?php
namespace
MongoDB\Tests
;
namespace
MongoDB\Tests
\Collection
;
use
MongoDB\Collection
;
use
MongoDB\Driver\Manager
;
use
MongoDB\Model\IndexInfo
;
use
MongoDB\Model\IndexInfo
;
use
InvalidArgumentException
;
use
InvalidArgumentException
;
class
CollectionFunctionalTest
extends
FunctionalTestCase
/**
* Functional tests for index management methods.
*
* @see https://github.com/mongodb/specifications/blob/master/source/index-management.rst
*/
class
IndexManagementFunctionalTest
extends
FunctionalTestCase
{
{
private
$collection
;
public
function
setUp
()
{
parent
::
setUp
();
$this
->
collection
=
new
Collection
(
$this
->
manager
,
$this
->
getNamespace
());
$this
->
collection
->
deleteMany
(
array
());
}
public
function
testDrop
()
{
$writeResult
=
$this
->
collection
->
insertOne
(
array
(
'x'
=>
1
));
$this
->
assertEquals
(
1
,
$writeResult
->
getInsertedCount
());
$commandResult
=
$this
->
collection
->
drop
();
$this
->
assertCommandSucceeded
(
$commandResult
);
$this
->
assertCollectionCount
(
$this
->
getNamespace
(),
0
);
}
function
testInsertAndRetrieve
()
{
$generator
=
new
FixtureGenerator
();
for
(
$i
=
0
;
$i
<
10
;
$i
++
)
{
$user
=
$generator
->
createUser
();
$result
=
$this
->
collection
->
insertOne
(
$user
);
$this
->
assertInstanceOf
(
'MongoDB\InsertOneResult'
,
$result
);
$this
->
assertInstanceOf
(
'BSON\ObjectId'
,
$result
->
getInsertedId
());
$this
->
assertEquals
(
24
,
strlen
(
$result
->
getInsertedId
()));
$user
[
"_id"
]
=
$result
->
getInsertedId
();
$document
=
$this
->
collection
->
findOne
(
array
(
"_id"
=>
$result
->
getInsertedId
()));
$this
->
assertEquals
(
$document
,
$user
,
"The inserted and returned objects are the same"
);
}
$this
->
assertEquals
(
10
,
$i
);
$query
=
array
(
"firstName"
=>
"Ransom"
);
$count
=
$this
->
collection
->
count
(
$query
);
$this
->
assertEquals
(
1
,
$count
);
$cursor
=
$this
->
collection
->
find
(
$query
);
$this
->
assertInstanceOf
(
'MongoDB\Driver\Cursor'
,
$cursor
);
foreach
(
$cursor
as
$n
=>
$person
)
{
$this
->
assertInternalType
(
"array"
,
$person
);
}
$this
->
assertEquals
(
0
,
$n
);
}
public
function
testCreateIndex
()
public
function
testCreateIndex
()
{
{
$that
=
$this
;
$that
=
$this
;
...
...
tests/DatabaseFunctionalTest.php
→
tests/Database
/CollectionManagement
FunctionalTest.php
View file @
c520df8a
<?php
<?php
namespace
MongoDB\Tests
;
namespace
MongoDB\Tests
\Database
;
use
MongoDB\Client
;
use
MongoDB\Database
;
use
MongoDB\Model\CollectionInfo
;
use
MongoDB\Model\CollectionInfo
;
use
InvalidArgumentException
;
use
InvalidArgumentException
;
/**
/**
* Functional tests for
the Database clas
s.
* Functional tests for
collection management method
s.
*/
*/
class
Database
FunctionalTest
extends
FunctionalTestCase
class
CollectionManagement
FunctionalTest
extends
FunctionalTestCase
{
{
private
$database
;
public
function
setUp
()
{
parent
::
setUp
();
$this
->
database
=
new
Database
(
$this
->
manager
,
$this
->
getDatabaseName
());
$this
->
database
->
drop
();
}
public
function
testCreateCollection
()
public
function
testCreateCollection
()
{
{
$that
=
$this
;
$that
=
$this
;
...
@@ -49,16 +37,6 @@ class DatabaseFunctionalTest extends FunctionalTestCase
...
@@ -49,16 +37,6 @@ class DatabaseFunctionalTest extends FunctionalTestCase
});
});
}
}
public
function
testDrop
()
{
$writeResult
=
$this
->
manager
->
executeInsert
(
$this
->
getNamespace
(),
array
(
'x'
=>
1
));
$this
->
assertEquals
(
1
,
$writeResult
->
getInsertedCount
());
$commandResult
=
$this
->
database
->
drop
();
$this
->
assertCommandSucceeded
(
$commandResult
);
$this
->
assertCollectionCount
(
$this
->
getNamespace
(),
0
);
}
public
function
testDropCollection
()
public
function
testDropCollection
()
{
{
$writeResult
=
$this
->
manager
->
executeInsert
(
$this
->
getNamespace
(),
array
(
'x'
=>
1
));
$writeResult
=
$this
->
manager
->
executeInsert
(
$this
->
getNamespace
(),
array
(
'x'
=>
1
));
...
...
tests/Database/DatabaseFunctionalTest.php
0 → 100644
View file @
c520df8a
<?php
namespace
MongoDB\Tests\Database
;
/**
* Functional tests for the Database class.
*/
class
DatabaseFunctionalTest
extends
FunctionalTestCase
{
public
function
testDrop
()
{
$writeResult
=
$this
->
manager
->
executeInsert
(
$this
->
getNamespace
(),
array
(
'x'
=>
1
));
$this
->
assertEquals
(
1
,
$writeResult
->
getInsertedCount
());
$commandResult
=
$this
->
database
->
drop
();
$this
->
assertCommandSucceeded
(
$commandResult
);
$this
->
assertCollectionCount
(
$this
->
getNamespace
(),
0
);
}
}
tests/Database/FunctionalTestCase.php
0 → 100644
View file @
c520df8a
<?php
namespace
MongoDB\Tests\Database
;
use
MongoDB\Database
;
use
MongoDB\Tests\FunctionalTestCase
as
BaseFunctionalTestCase
;
/**
* Base class for Database functional tests.
*/
abstract
class
FunctionalTestCase
extends
BaseFunctionalTestCase
{
protected
$database
;
public
function
setUp
()
{
parent
::
setUp
();
$this
->
database
=
new
Database
(
$this
->
manager
,
$this
->
getDatabaseName
());
$this
->
database
->
drop
();
}
}
tests/FunctionalTestCase.php
View file @
c520df8a
...
@@ -15,7 +15,7 @@ abstract class FunctionalTestCase extends TestCase
...
@@ -15,7 +15,7 @@ abstract class FunctionalTestCase extends TestCase
$this
->
manager
=
new
Manager
(
$this
->
getUri
());
$this
->
manager
=
new
Manager
(
$this
->
getUri
());
}
}
p
ublic
function
assertCollectionCount
(
$namespace
,
$count
)
p
rotected
function
assertCollectionCount
(
$namespace
,
$count
)
{
{
list
(
$databaseName
,
$collectionName
)
=
explode
(
'.'
,
$namespace
,
2
);
list
(
$databaseName
,
$collectionName
)
=
explode
(
'.'
,
$namespace
,
2
);
...
@@ -26,7 +26,7 @@ abstract class FunctionalTestCase extends TestCase
...
@@ -26,7 +26,7 @@ abstract class FunctionalTestCase extends TestCase
$this
->
assertEquals
(
$count
,
$document
[
'n'
]);
$this
->
assertEquals
(
$count
,
$document
[
'n'
]);
}
}
p
ublic
function
assertCommandSucceeded
(
Cursor
$cursor
)
p
rotected
function
assertCommandSucceeded
(
Cursor
$cursor
)
{
{
$document
=
current
(
$cursor
->
toArray
());
$document
=
current
(
$cursor
->
toArray
());
$this
->
assertArrayHasKey
(
'ok'
,
$document
);
$this
->
assertArrayHasKey
(
'ok'
,
$document
);
...
...
tests/TestCase.php
View file @
c520df8a
...
@@ -11,7 +11,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
...
@@ -11,7 +11,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
*
*
* @return string
* @return string
*/
*/
p
ublic
function
getCollectionName
()
p
rotected
function
getCollectionName
()
{
{
$class
=
new
ReflectionClass
(
$this
);
$class
=
new
ReflectionClass
(
$this
);
...
@@ -23,7 +23,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
...
@@ -23,7 +23,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
*
*
* @return string
* @return string
*/
*/
p
ublic
function
getDatabaseName
()
p
rotected
function
getDatabaseName
()
{
{
return
getenv
(
'MONGODB_DATABASE'
)
?:
'phplib_test'
;
return
getenv
(
'MONGODB_DATABASE'
)
?:
'phplib_test'
;
}
}
...
@@ -33,7 +33,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
...
@@ -33,7 +33,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
*
*
* @return string
* @return string
*/
*/
p
ublic
function
getNamespace
()
p
rotected
function
getNamespace
()
{
{
return
sprintf
(
'%s.%s'
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
return
sprintf
(
'%s.%s'
,
$this
->
getDatabaseName
(),
$this
->
getCollectionName
());
}
}
...
@@ -43,7 +43,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
...
@@ -43,7 +43,7 @@ abstract class TestCase extends \PHPUnit_Framework_TestCase
*
*
* @return string
* @return string
*/
*/
p
ublic
function
getUri
()
p
rotected
function
getUri
()
{
{
return
getenv
(
'MONGODB_URI'
)
?:
'mongodb://127.0.0.1:27017'
;
return
getenv
(
'MONGODB_URI'
)
?:
'mongodb://127.0.0.1:27017'
;
}
}
...
...
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