Commit d3a3c4e8 authored by Jeremy Mikola's avatar Jeremy Mikola

Merge pull request #453

parents 6523cc6a b964f3ea
...@@ -61,7 +61,6 @@ matrix: ...@@ -61,7 +61,6 @@ matrix:
before_script: before_script:
- mongod --version - mongod --version
- mongo --eval 'var v = db.runCommand({buildInfo:1}).versionArray; if ((v[0] == 3 && v[1] >= 4) || v[0] >= 4) db.adminCommand({setFeatureCompatibilityVersion:"3.4"});'
- pecl install -f mongodb-${DRIVER_VERSION} - pecl install -f mongodb-${DRIVER_VERSION}
- php --ri mongodb - php --ri mongodb
- composer install --dev --no-interaction --prefer-source - composer install --dev --no-interaction --prefer-source
......
...@@ -11,6 +11,7 @@ use MongoDB\Model\BSONDocument; ...@@ -11,6 +11,7 @@ use MongoDB\Model\BSONDocument;
use InvalidArgumentException; use InvalidArgumentException;
use stdClass; use stdClass;
use Traversable; use Traversable;
use UnexpectedValueException;
abstract class FunctionalTestCase extends TestCase abstract class FunctionalTestCase extends TestCase
{ {
...@@ -76,22 +77,34 @@ abstract class FunctionalTestCase extends TestCase ...@@ -76,22 +77,34 @@ abstract class FunctionalTestCase extends TestCase
); );
} }
protected function getFeatureCompatibilityVersion() protected function getFeatureCompatibilityVersion(ReadPreference $readPreference = null)
{ {
if (version_compare($this->getServerVersion(), '3.4.0', '<')) { if (version_compare($this->getServerVersion(), '3.4.0', '<')) {
return $this->getServerVersion(); return $this->getServerVersion($readPreference);
} }
$cursor = $this->manager->executeCommand( $cursor = $this->manager->executeCommand(
"admin", 'admin',
new Command(['getParameter' => 1, 'featureCompatibilityVersion' => 1]) new Command(['getParameter' => 1, 'featureCompatibilityVersion' => 1]),
$readPreference ?: new ReadPreference(ReadPreference::RP_PRIMARY)
); );
$cursor->setTypeMap(['root' => 'array', 'document' => 'array']); $cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
$document = current($cursor->toArray()); $document = current($cursor->toArray());
// MongoDB 3.6: featureCompatibilityVersion is an embedded document
if (isset($document['featureCompatibilityVersion']['version']) && is_string($document['featureCompatibilityVersion']['version'])) {
return $document['featureCompatibilityVersion']['version']; return $document['featureCompatibilityVersion']['version'];
} }
// MongoDB 3.4: featureCompatibilityVersion is a string
if (isset($document['featureCompatibilityVersion']) && is_string($document['featureCompatibilityVersion'])) {
return $document['featureCompatibilityVersion'];
}
throw new UnexpectedValueException('Could not determine featureCompatibilityVersion');
}
protected function getPrimaryServer() protected function getPrimaryServer()
{ {
return $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY)); return $this->manager->selectServer(new ReadPreference(ReadPreference::RP_PRIMARY));
...@@ -108,9 +121,13 @@ abstract class FunctionalTestCase extends TestCase ...@@ -108,9 +121,13 @@ abstract class FunctionalTestCase extends TestCase
$cursor->setTypeMap(['root' => 'array', 'document' => 'array']); $cursor->setTypeMap(['root' => 'array', 'document' => 'array']);
$document = current($cursor->toArray()); $document = current($cursor->toArray());
if (isset($document['version']) && is_string($document['version'])) {
return $document['version']; return $document['version'];
} }
throw new UnexpectedValueException('Could not determine server version');
}
/** /**
* Normalizes a BSON document or array for use with assertEquals(). * Normalizes a BSON document or array for use with assertEquals().
* *
......
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