Skip to content

Commit

Permalink
Merge pull request #186 from alcaeus/test-beta1
Browse files Browse the repository at this point in the history
Test against mongodb-1.3.0beta1
  • Loading branch information
alcaeus committed Aug 19, 2017
2 parents 052cd5d + 5de3c3f commit 6b489a7
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 66 deletions.
57 changes: 21 additions & 36 deletions .travis.yml
@@ -1,9 +1,28 @@
dist: trusty
sudo: false
language: php

services:
- mongodb

php:
- 5.6
- 7.0
- 7.1
- 7.2

env:
global:
- DRIVER_VERSION="stable"

addons:
apt:
sources:
- sourceline: "deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.4 multiverse"
key_url: "https://www.mongodb.org/static/pgp/server-3.4.asc"
- "mongodb-upstart"
packages: ['mongodb-org-server']

matrix:
fast_finish: true
include:
Expand All @@ -12,46 +31,12 @@ matrix:
addons:
apt:
sources:
- sourceline: "deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.0 multiverse"
- sourceline: "deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse"
key_url: "https://www.mongodb.org/static/pgp/server-3.0.asc"
- "mongodb-upstart"
packages: ['mongodb-org-server']
- php: 5.6
env: DRIVER_VERSION=stable
addons:
apt:
sources:
- sourceline: "deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.4 multiverse"
key_url: "https://www.mongodb.org/static/pgp/server-3.4.asc"
- "mongodb-upstart"
packages: ['mongodb-org-server']
- php: 7.0
env: DRIVER_VERSION=stable
addons:
apt:
sources:
- sourceline: "deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.4 multiverse"
key_url: "https://www.mongodb.org/static/pgp/server-3.4.asc"
- "mongodb-upstart"
packages: ['mongodb-org-server']
- php: 7.1
env: DRIVER_VERSION=stable
addons:
apt:
sources:
- sourceline: "deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.4 multiverse"
key_url: "https://www.mongodb.org/static/pgp/server-3.4.asc"
- "mongodb-upstart"
packages: ['mongodb-org-server']
- php: 7.2
env: DRIVER_VERSION=stable
addons:
apt:
sources:
- sourceline: "deb [arch=amd64] https://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.4 multiverse"
key_url: "https://www.mongodb.org/static/pgp/server-3.4.asc"
- "mongodb-upstart"
packages: ['mongodb-org-server']
env: DRIVER_VERSION="1.3.0beta1"

before_install:
- pecl install -f mongodb-${DRIVER_VERSION}
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG-1.1.md
Expand Up @@ -3,6 +3,17 @@ CHANGELOG for 1.1.x

This changelog references the relevant changes done in minor version updates.

1.1.3 (xxxx-xx-xx)
------------------

All issues and pull requests under this release may be found under the
[1.1.3](https://github.com/alcaeus/mongo-php-adapter/issues?q=milestone%3A1.1.3)
milestone.

* [#186](https://github.com/alcaeus/mongo-php-adapter/pull/186) fixes errors when
using the 1.3 beta version of `ext-mongodb`. It also fixes an issue where new
fields in `MongoDB::listCollections` were not properly reported.

1.1.2 (2017-08-04)
------------------

Expand Down
15 changes: 8 additions & 7 deletions lib/Mongo/MongoClient.php
Expand Up @@ -86,6 +86,10 @@ public function __construct($server = 'default', array $options = ['connect' =>
$server = 'mongodb://' . self::DEFAULT_HOST . ':' . self::DEFAULT_PORT;
}

if (isset($options['readPreferenceTags'])) {
$options['readPreferenceTags'] = [$this->getReadPreferenceTags($options['readPreferenceTags'])];
}

$this->applyConnectionOptions($server, $options);

$this->server = $server;
Expand Down Expand Up @@ -409,13 +413,10 @@ private function applyConnectionOptions($server, array $options)
unset($options['wTimeout']);
}

if (isset($options['readPreferenceTags'])) {
$options['readPreferenceTags'] = [$this->getReadPreferenceTags($options['readPreferenceTags'])];

// Special handling for readPreferenceTags which are merged
if (isset($urlOptions['readPreferenceTags'])) {
$options['readPreferenceTags'] = array_merge($urlOptions['readPreferenceTags'], $options['readPreferenceTags']);
}
// Special handling for readPreferenceTags which are merged
if (isset($options['readPreferenceTags']) && isset($urlOptions['readPreferenceTags'])) {
$options['readPreferenceTags'] = array_merge($urlOptions['readPreferenceTags'], $options['readPreferenceTags']);
unset($urlOptions['readPreferenceTags']);
}

$urlOptions = array_merge($urlOptions, $options);
Expand Down
17 changes: 13 additions & 4 deletions lib/Mongo/MongoDB.php
Expand Up @@ -143,10 +143,19 @@ public function getCollectionInfo(array $options = [])
}

$getCollectionInfo = function (CollectionInfo $collectionInfo) {
return [
'name' => $collectionInfo->getName(),
'options' => $collectionInfo->getOptions(),
];
// @todo do away with __debugInfo once https://jira.mongodb.org/browse/PHPLIB-226 is fixed
$info = $collectionInfo->__debugInfo();

return array_filter(
[
'name' => $collectionInfo->getName(),
'type' => isset($info['type']) ? $info['type'] : null,
'options' => $collectionInfo->getOptions(),
'info' => isset($info['info']) ? (array) $info['info'] : null,
'idIndex' => isset($info['idIndex']) ? (array) $info['idIndex'] : null,
],
function ($item) { return $item !== null; }
);
};

$eligibleCollections = array_filter(
Expand Down
12 changes: 7 additions & 5 deletions tests/Alcaeus/MongoDbAdapter/Mongo/MongoBinDataTest.php
Expand Up @@ -10,10 +10,12 @@
*/
class MongoBinDataTest extends TestCase
{
const GUID = '0123456789abcdef';

public function testCreate()
{
$bin = new \MongoBinData('foo', \MongoBinData::FUNC);
$this->assertAttributeSame('foo', 'bin', $bin);
$bin = new \MongoBinData(self::GUID, \MongoBinData::FUNC);
$this->assertAttributeSame(self::GUID, 'bin', $bin);
$this->assertAttributeSame(\MongoBinData::FUNC, 'type', $bin);

$this->assertSame('<Mongo Binary Data>', (string)$bin);
Expand All @@ -31,18 +33,18 @@ public function testConvertToBson(\MongoBinData $bin)
$bsonBinary = $bin->toBSONType();
$this->assertInstanceOf('MongoDB\BSON\Binary', $bsonBinary);

$this->assertSame('foo', $bsonBinary->getData());
$this->assertSame(self::GUID, $bsonBinary->getData());
$this->assertSame(\MongoDB\BSON\Binary::TYPE_FUNCTION, $bsonBinary->getType());
}

public function testCreateWithBsonBinary()
{
$this->skipTestUnless(in_array(TypeInterface::class, class_implements('MongoBinData')));

$bsonBinary = new \MongoDB\BSON\Binary('foo', \MongoDB\BSON\Binary::TYPE_UUID);
$bsonBinary = new \MongoDB\BSON\Binary(self::GUID, \MongoDB\BSON\Binary::TYPE_UUID);
$bin = new \MongoBinData($bsonBinary);

$this->assertAttributeSame('foo', 'bin', $bin);
$this->assertAttributeSame(self::GUID, 'bin', $bin);
$this->assertAttributeSame(\MongoBinData::UUID_RFC4122, 'type', $bin);
}
}
24 changes: 13 additions & 11 deletions tests/Alcaeus/MongoDbAdapter/Mongo/MongoCollectionTest.php
Expand Up @@ -34,7 +34,7 @@ public function testCreateRecord()
'errmsg' => null,
];
$document = ['foo' => 'bar'];
$this->assertSame($expected, $collection->insert($document));
$this->assertEquals($expected, $collection->insert($document));

$this->assertInstanceOf('MongoId', $document['_id']);
$id = (string) $document['_id'];
Expand Down Expand Up @@ -152,7 +152,7 @@ public function testUnacknowledgedWriteWithBooleanValue()
public function testAcknowledgedWriteConcernWithBool()
{
$document = ['foo' => 'bar'];
$this->assertSame(
$this->assertEquals(
[
'ok' => 1.0,
'n' => 0,
Expand Down Expand Up @@ -316,7 +316,7 @@ public function testUpdateOne()
];

$result = $this->getCollection()->update(['foo' => 'bar'], ['$set' => ['foo' => 'foo']]);
$this->assertSame($expected, $result);
$this->assertEquals($expected, $result);

$this->assertSame(1, $this->getCheckDatabase()->selectCollection('test')->count(['foo' => 'foo']));
}
Expand All @@ -340,7 +340,7 @@ public function testUpdateReplaceOne()
];

$result = $this->getCollection()->update(['foo' => 'bar'], ['foo' => 'foo']);
$this->assertSame($expected, $result);
$this->assertEquals($expected, $result);

$this->assertSame(1, $this->getCheckDatabase()->selectCollection('test')->count(['foo' => 'foo']));
$this->assertSame(1, $this->getCheckDatabase()->selectCollection('test')->count(['bar' => 'foo']));
Expand Down Expand Up @@ -387,7 +387,7 @@ public function testUpdateMany()
];

$result = $this->getCollection()->update(['change' => true], ['$set' => ['foo' => 'foo']], ['multiple' => true]);
$this->assertSame($expected, $result);
$this->assertEquals($expected, $result);

$this->assertSame(3, $this->getCheckDatabase()->selectCollection('test')->count(['foo' => 'foo']));
}
Expand Down Expand Up @@ -420,7 +420,7 @@ public function testRemoveMultiple()
];

$result = $this->getCollection()->remove(['foo' => 'bar']);
$this->assertSame($expected, $result);
$this->assertEquals($expected, $result);

$this->assertSame(1, $this->getCheckDatabase()->selectCollection('test')->count());
}
Expand All @@ -441,7 +441,7 @@ public function testRemoveSingle()
];

$result = $this->getCollection()->remove(['foo' => 'bar'], ['justOne' => true]);
$this->assertSame($expected, $result);
$this->assertEquals($expected, $result);

$this->assertSame(2, $this->getCheckDatabase()->selectCollection('test')->count());
}
Expand Down Expand Up @@ -665,7 +665,7 @@ public function testFindOneConnectionIssue()
{
$this->expectException(\MongoConnectionException::class);

$client = $this->getClient([], 'mongodb://localhost:28888?connectTimeoutMS=1');
$client = $this->getClient([], 'mongodb://localhost:28888/?connectTimeoutMS=1');
$collection = $client->selectCollection('mongo-php-adapter', 'test');

$collection->findOne();
Expand Down Expand Up @@ -976,7 +976,7 @@ public function testSaveUpdate()
$insertDocument = ['_id' => new \MongoId($id), 'foo' => 'bar'];
$saveDocument = ['_id' => new \MongoId($id), 'foo' => 'foo'];
$collection->insert($insertDocument);
$this->assertSame($expected, $collection->save($saveDocument));
$this->assertEquals($expected, $collection->save($saveDocument));

$newCollection = $this->getCheckDatabase()->selectCollection('test');
$this->assertSame(1, $newCollection->count());
Expand Down Expand Up @@ -1267,7 +1267,8 @@ public function testDeleteIndexUsingIndexName()
$expected['code'] = 27;
}

$this->assertEquals($expected, $this->getCollection()->deleteIndex('bar'));
// Using assertArraySubset because newer versions (3.4.7?) also return `codeName`
$this->assertArraySubset($expected, $this->getCollection()->deleteIndex('bar'));

$this->assertCount(2, iterator_to_array($newCollection->listIndexes()));
}
Expand Down Expand Up @@ -1326,7 +1327,8 @@ public function testDeleteIndexesForNonExistingCollection()
$expected['code'] = 26;
}

$this->assertSame($expected, $this->getCollection('nonExisting')->deleteIndexes());
// Using assertArraySubset because newer versions (3.4.7?) also return `codeName`
$this->assertArraySubset($expected, $this->getCollection('nonExisting')->deleteIndexes());
}

public function dataGetIndexInfo()
Expand Down
22 changes: 20 additions & 2 deletions tests/Alcaeus/MongoDbAdapter/Mongo/MongoDBTest.php
Expand Up @@ -126,7 +126,8 @@ public function testCommandError()
'code' => 13,
];

$this->assertEquals($expected, $db->command(['listDatabases' => 1]));
// Using assertArraySubset because newer versions (3.4.7?) also return `codeName`
$this->assertArraySubset($expected, $db->command(['listDatabases' => 1]));
}

public function testCommandCursorTimeout()
Expand Down Expand Up @@ -273,7 +274,24 @@ public function testGetCollectionInfo()

foreach ($this->getDatabase()->getCollectionInfo() as $collectionInfo) {
if ($collectionInfo['name'] === 'test') {
$this->assertSame(['name' => 'test', 'options' => []], $collectionInfo);
$expected = [
'name' => 'test',
'options' => []
];

if (version_compare($this->getServerVersion(), '3.4.0', '>=')) {
$expected += [
'type' => 'collection',
'info' => ['readOnly' => false],
'idIndex' => [
'v' => $this->getDefaultIndexVersion(),
'key' => ['_id' => 1],
'name' => '_id_',
'ns' => (string) $this->getCollection(),
],
];
}
$this->assertEquals($expected, $collectionInfo);
return;
}
}
Expand Down
20 changes: 19 additions & 1 deletion tests/Alcaeus/MongoDbAdapter/TestCase.php
Expand Up @@ -7,6 +7,9 @@

abstract class TestCase extends BaseTestCase
{
const INDEX_VERSION_1 = 1;
const INDEX_VERSION_2 = 2;

protected function tearDown()
{
$this->getCheckDatabase()->drop();
Expand Down Expand Up @@ -174,13 +177,28 @@ protected function getServerVersion()
return $serverInfo['version'];
}

/**
* @return string
*/
protected function getFeatureCompatibilityVersion()
{
$featureCompatibilityVersion = $this->getClient()->selectDB('admin')->command(['getParameter' => true, 'featureCompatibilityVersion' => true]);
return isset($featureCompatibilityVersion['featureCompatibilityVersion']) ? $featureCompatibilityVersion['featureCompatibilityVersion'] : '3.2';
}

/**
* Indexes created in MongoDB 3.4 default to v: 2.
* @return int
* @see https://docs.mongodb.com/manual/release-notes/3.4-compatibility/#backwards-incompatible-features
*/
protected function getDefaultIndexVersion()
{
return version_compare($this->getServerVersion(), '3.4.0', '>=') ? 2 : 1;
if (version_compare($this->getServerVersion(), '3.4.0', '<')) {
self::INDEX_VERSION_1;
}

// Check featureCompatibilityFlag
$compatibilityVersion = $this->getFeatureCompatibilityVersion();
return $compatibilityVersion === '3.4' ? self::INDEX_VERSION_2 : self::INDEX_VERSION_1;
}
}

0 comments on commit 6b489a7

Please sign in to comment.