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
87cd9899
Commit
87cd9899
authored
Mar 17, 2015
by
Jeremy Mikola
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-58: Functional tests for CRUD spec read methods
parent
c991d3a3
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
224 additions
and
0 deletions
+224
-0
AggregateFunctionalTest.php
tests/Collection/CrudSpec/AggregateFunctionalTest.php
+59
-0
CountFunctionalTest.php
tests/Collection/CrudSpec/CountFunctionalTest.php
+38
-0
DistinctFunctionalTest.php
tests/Collection/CrudSpec/DistinctFunctionalTest.php
+30
-0
FindFunctionalTest.php
tests/Collection/CrudSpec/FindFunctionalTest.php
+64
-0
FunctionalTestCase.php
tests/Collection/CrudSpec/FunctionalTestCase.php
+33
-0
No files found.
tests/Collection/CrudSpec/AggregateFunctionalTest.php
0 → 100644
View file @
87cd9899
<?php
namespace
MongoDB\Tests\Collection\CrudSpec
;
use
MongoDB\Collection
;
/**
* CRUD spec functional tests for aggregate().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class
AggregateFunctionalTest
extends
FunctionalTestCase
{
public
function
setUp
()
{
parent
::
setUp
();
$this
->
createFixtures
(
3
);
}
public
function
testAggregateWithMultipleStages
()
{
$cursor
=
$this
->
collection
->
aggregate
(
array
(
array
(
'$sort'
=>
array
(
'x'
=>
1
)),
array
(
'$match'
=>
array
(
'_id'
=>
array
(
'$gt'
=>
1
))),
),
array
(
'batchSize'
=>
2
)
);
$expected
=
array
(
array
(
'_id'
=>
2
,
'x'
=>
22
),
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$cursor
->
toArray
());
}
public
function
testAggregateWithOut
()
{
$outputCollection
=
new
Collection
(
$this
->
manager
,
$this
->
getNamespace
()
.
'_output'
);
$this
->
dropCollectionIfItExists
(
$outputCollection
);
$this
->
collection
->
aggregate
(
array
(
array
(
'$sort'
=>
array
(
'x'
=>
1
)),
array
(
'$match'
=>
array
(
'_id'
=>
array
(
'$gt'
=>
1
))),
array
(
'$out'
=>
$outputCollection
->
getCollectionName
()),
)
);
$expected
=
array
(
array
(
'_id'
=>
2
,
'x'
=>
22
),
array
(
'_id'
=>
3
,
'x'
=>
33
),
);
$this
->
assertSame
(
$expected
,
$outputCollection
->
find
()
->
toArray
());
}
}
tests/Collection/CrudSpec/CountFunctionalTest.php
0 → 100644
View file @
87cd9899
<?php
namespace
MongoDB\Tests\Collection\CrudSpec
;
/**
* CRUD spec functional tests for count().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class
CountFunctionalTest
extends
FunctionalTestCase
{
public
function
setUp
()
{
parent
::
setUp
();
$this
->
createFixtures
(
3
);
}
public
function
testCountWithoutFilter
()
{
$this
->
assertSame
(
3
,
$this
->
collection
->
count
());
}
public
function
testCountWithFilter
()
{
$filter
=
array
(
'_id'
=>
array
(
'$gt'
=>
1
));
$this
->
assertSame
(
2
,
$this
->
collection
->
count
(
$filter
));
}
public
function
testCountWithSkipAndLimit
()
{
$filter
=
array
();
$options
=
array
(
'skip'
=>
1
,
'limit'
=>
3
);
$this
->
assertSame
(
2
,
$this
->
collection
->
count
(
$filter
,
$options
));
}
}
tests/Collection/CrudSpec/DistinctFunctionalTest.php
0 → 100644
View file @
87cd9899
<?php
namespace
MongoDB\Tests\Collection\CrudSpec
;
/**
* CRUD spec functional tests for distinct().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class
DistinctFunctionalTest
extends
FunctionalTestCase
{
public
function
setUp
()
{
parent
::
setUp
();
$this
->
createFixtures
(
3
);
}
public
function
testDistinctWithoutFilter
()
{
$this
->
assertSame
(
array
(
11
,
22
,
33
),
$this
->
collection
->
distinct
(
'x'
));
}
public
function
testDistinctWithFilter
()
{
$filter
=
array
(
'_id'
=>
array
(
'$gt'
=>
1
));
$this
->
assertSame
(
array
(
22
,
33
),
$this
->
collection
->
distinct
(
'x'
,
$filter
));
}
}
tests/Collection/CrudSpec/FindFunctionalTest.php
0 → 100644
View file @
87cd9899
<?php
namespace
MongoDB\Tests\Collection\CrudSpec
;
/**
* CRUD spec functional tests for find().
*
* @see https://github.com/mongodb/specifications/tree/master/source/crud/tests
*/
class
FindFunctionalTest
extends
FunctionalTestCase
{
public
function
setUp
()
{
parent
::
setUp
();
$this
->
createFixtures
(
5
);
}
public
function
testFindWithFilter
()
{
$filter
=
array
(
'_id'
=>
1
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
(
$filter
)
->
toArray
());
}
public
function
testFindWithFilterSortSkipAndLimit
()
{
$filter
=
array
(
'_id'
=>
array
(
'$gt'
=>
2
));
$options
=
array
(
'sort'
=>
array
(
'_id'
=>
1
),
'skip'
=>
2
,
'limit'
=>
2
,
);
$expected
=
array
(
array
(
'_id'
=>
5
,
'x'
=>
55
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
(
$filter
,
$options
)
->
toArray
());
}
public
function
testFindWithLimitSortAndBatchSize
()
{
$filter
=
array
();
$options
=
array
(
'sort'
=>
array
(
'_id'
=>
1
),
'limit'
=>
4
,
'batchSize'
=>
2
,
);
$expected
=
array
(
array
(
'_id'
=>
1
,
'x'
=>
11
),
array
(
'_id'
=>
2
,
'x'
=>
22
),
array
(
'_id'
=>
3
,
'x'
=>
33
),
array
(
'_id'
=>
4
,
'x'
=>
44
),
);
$this
->
assertSame
(
$expected
,
$this
->
collection
->
find
(
$filter
,
$options
)
->
toArray
());
}
}
tests/Collection/CrudSpec/FunctionalTestCase.php
0 → 100644
View file @
87cd9899
<?php
namespace
MongoDB\Tests\Collection\CrudSpec
;
use
MongoDB\Driver\BulkWrite
;
use
MongoDB\Tests\Collection\FunctionalTestCase
as
BaseFunctionalTestCase
;
/**
* Base class for Collection CRUD spec functional tests.
*/
abstract
class
FunctionalTestCase
extends
BaseFunctionalTestCase
{
/**
* Create data fixtures.
*
* @param integer $n
*/
protected
function
createFixtures
(
$n
)
{
$bulkWrite
=
new
BulkWrite
(
true
);
for
(
$i
=
1
;
$i
<=
$n
;
$i
++
)
{
$bulkWrite
->
insert
(
array
(
'_id'
=>
$i
,
'x'
=>
(
integer
)
(
$i
.
$i
),
));
}
$result
=
$this
->
manager
->
executeBulkWrite
(
$this
->
getNamespace
(),
$bulkWrite
);
$this
->
assertEquals
(
$n
,
$result
->
getInsertedCount
());
}
}
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