Unverified Commit 68d49083 authored by Andreas Braun's avatar Andreas Braun

Merge pull request #723

parents 546f9282 ea753036
......@@ -91,6 +91,12 @@ jobs:
env:
- SERVER_VERSION=4.0.12
# Test upcoming server version
- stage: Test
php: "7.3"
env:
- SERVER_VERSION=4.3.3
# Test other server configurations
- stage: Test
php: "7.3"
......
......@@ -55,8 +55,8 @@ class MapReduceResult implements IteratorAggregate
public function __construct(callable $getIterator, stdClass $result)
{
$this->getIterator = $getIterator;
$this->executionTimeMS = (integer) $result->timeMillis;
$this->counts = (array) $result->counts;
$this->executionTimeMS = isset($result->timeMillis) ? (integer) $result->timeMillis : 0;
$this->counts = isset($result->counts) ? (array) $result->counts : [];
$this->timing = isset($result->timing) ? (array) $result->timing : [];
}
......
......@@ -18,6 +18,7 @@
namespace MongoDB\Model;
use IteratorIterator;
use Traversable;
/**
* CollectionInfoIterator for listCollections command results.
......@@ -32,6 +33,19 @@ use IteratorIterator;
*/
class CollectionInfoCommandIterator extends IteratorIterator implements CollectionInfoIterator
{
/** @var string|null */
private $databaseName;
/**
* @param string|null $databaseName
*/
public function __construct(Traversable $iterator, $databaseName = null)
{
parent::__construct($iterator);
$this->databaseName = $databaseName;
}
/**
* Return the current element as a CollectionInfo instance.
*
......@@ -41,6 +55,12 @@ class CollectionInfoCommandIterator extends IteratorIterator implements Collecti
*/
public function current()
{
return new CollectionInfo(parent::current());
$info = parent::current();
if ($this->databaseName !== null && isset($info['idIndex']) && ! isset($info['idIndex']['ns'])) {
$info['idIndex']['ns'] = $this->databaseName . '.' . $info['name'];
}
return new CollectionInfo($info);
}
}
......@@ -136,6 +136,6 @@ class ListCollections implements Executable
$cursor = $server->executeReadCommand($this->databaseName, new Command($cmd), $this->createOptions());
$cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
return new CollectionInfoCommandIterator(new CachingIterator($cursor));
return new CollectionInfoCommandIterator(new CachingIterator($cursor), $this->databaseName);
}
}
......@@ -396,8 +396,10 @@ class CollectionFunctionalTest extends FunctionalTestCase
$this->assertSameDocuments($expected, $result);
$this->assertGreaterThanOrEqual(0, $result->getExecutionTimeMS());
$this->assertNotEmpty($result->getCounts());
if (version_compare($this->getServerVersion(), '4.3.0', '<')) {
$this->assertGreaterThanOrEqual(0, $result->getExecutionTimeMS());
$this->assertNotEmpty($result->getCounts());
}
}
public function collectionMethodClosures()
......
......@@ -9,7 +9,9 @@ use MongoDB\Operation\DropCollection;
use MongoDB\Operation\Find;
use MongoDB\Operation\MapReduce;
use MongoDB\Tests\CommandObserver;
use function is_object;
use function iterator_to_array;
use function usort;
use function version_compare;
class MapReduceFunctionalTest extends FunctionalTestCase
......@@ -92,12 +94,19 @@ class MapReduceFunctionalTest extends FunctionalTestCase
$result = $operation->execute($this->getPrimaryServer());
$this->assertInstanceOf(MapReduceResult::class, $result);
$this->assertGreaterThanOrEqual(0, $result->getExecutionTimeMS());
$this->assertNotEmpty($result->getCounts());
if (version_compare($this->getServerVersion(), '4.3.0', '<')) {
$this->assertGreaterThanOrEqual(0, $result->getExecutionTimeMS());
$this->assertNotEmpty($result->getCounts());
}
}
public function testResultIncludesTimingWithVerboseOption()
{
if (version_compare($this->getServerVersion(), '4.3.0', '>=')) {
$this->markTestSkipped('mapReduce statistics are no longer exposed');
}
$this->createFixtures(3);
$map = new Javascript('function() { emit(this.x, this.y); }');
......@@ -115,6 +124,10 @@ class MapReduceFunctionalTest extends FunctionalTestCase
public function testResultDoesNotIncludeTimingWithoutVerboseOption()
{
if (version_compare($this->getServerVersion(), '4.3.0', '>=')) {
$this->markTestSkipped('mapReduce statistics are no longer exposed');
}
$this->createFixtures(3);
$map = new Javascript('function() { emit(this.x, this.y); }');
......@@ -226,7 +239,7 @@ class MapReduceFunctionalTest extends FunctionalTestCase
$operation = new MapReduce($this->getDatabaseName(), $this->getCollectionName(), $map, $reduce, $out, ['typeMap' => $typeMap]);
$results = iterator_to_array($operation->execute($this->getPrimaryServer()));
$this->assertEquals($expectedDocuments, $results);
$this->assertEquals($this->sortResults($expectedDocuments), $this->sortResults($results));
}
public function provideTypeMapOptionsAndExpectedDocuments()
......@@ -273,12 +286,12 @@ class MapReduceFunctionalTest extends FunctionalTestCase
$operation = new MapReduce($this->getDatabaseName(), $this->getCollectionName(), $map, $reduce, $out, ['typeMap' => $typeMap]);
$results = iterator_to_array($operation->execute($this->getPrimaryServer()));
$this->assertEquals($expectedDocuments, $results);
$this->assertEquals($this->sortResults($expectedDocuments), $this->sortResults($results));
$operation = new Find($this->getDatabaseName(), $out, [], ['typeMap' => $typeMap]);
$cursor = $operation->execute($this->getPrimaryServer());
$this->assertEquals($expectedDocuments, iterator_to_array($cursor));
$this->assertEquals($this->sortResults($expectedDocuments), $this->sortResults(iterator_to_array($cursor)));
$operation = new DropCollection($this->getDatabaseName(), $out);
$operation->execute($this->getPrimaryServer());
......@@ -302,4 +315,19 @@ class MapReduceFunctionalTest extends FunctionalTestCase
$this->assertEquals($n * 2, $result->getInsertedCount());
}
private function sortResults(array $results) : array
{
$sortFunction = static function ($resultA, $resultB) : int {
$idA = is_object($resultA) ? $resultA->_id : $resultA['_id'];
$idB = is_object($resultB) ? $resultB->_id : $resultB['_id'];
return $idA <=> $idB;
};
$sortedResults = $results;
usort($sortedResults, $sortFunction);
return $sortedResults;
}
}
......@@ -14,6 +14,13 @@ use function glob;
*/
class CrudSpecTest extends FunctionalTestCase
{
/** @var array */
private static $incompleteTests = [
'find-allowdiskuse: Find does not send allowDiskuse when value is not specified' => 'PHPLIB-500',
'find-allowdiskuse: Find sends allowDiskuse false when false is specified' => 'PHPLIB-500',
'find-allowdiskuse: Find sends allowDiskUse true when true is specified' => 'PHPLIB-500',
];
/**
* Assert that the expected and actual command documents match.
*
......@@ -37,6 +44,10 @@ class CrudSpecTest extends FunctionalTestCase
*/
public function testCrud(stdClass $test, array $runOn = null, array $data, $databaseName = null, $collectionName = null)
{
if (isset(self::$incompleteTests[$this->dataDescription()])) {
$this->markTestIncomplete(self::$incompleteTests[$this->dataDescription()]);
}
if (isset($runOn)) {
$this->checkServerRequirements($runOn);
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment