Skip to content

Updates for PHPC and HHVM 1.0.0 #42

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 2, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ env:
- MONGO_REPO_TYPE="precise/mongodb-enterprise/"
- SOURCES_LOC="/etc/apt/sources.list.d/mongodb.list"
matrix:
- DRIVER_VERSION=beta SERVER_VERSION=2.4
- DRIVER_VERSION=beta SERVER_VERSION=2.6
- DRIVER_VERSION=beta SERVER_VERSION=3.0
- DRIVER_VERSION=1.0 SERVER_VERSION=2.4
- DRIVER_VERSION=1.0 SERVER_VERSION=2.6
- DRIVER_VERSION=1.0 SERVER_VERSION=3.0

before_install:
- sudo apt-key adv --keyserver ${KEY_SERVER} --recv 7F0CEB10
Expand Down
8 changes: 4 additions & 4 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public function listDatabases(array $options = array())
public function selectCollection($databaseName, $collectionName, WriteConcern $writeConcern = null, ReadPreference $readPreference = null)
{
$namespace = $databaseName . '.' . $collectionName;
$writeConcern = $writeConcern ?: \MongoDB\get_manager_write_concern($this->manager);
$readPreference = $readPreference ?: \MongoDB\get_manager_read_preference($this->manager);
$writeConcern = $writeConcern ?: $this->manager->getWriteConcern();
$readPreference = $readPreference ?: $this->manager->getReadPreference();

return new Collection($this->manager, $namespace, $writeConcern, $readPreference);
}
Expand All @@ -94,8 +94,8 @@ public function selectCollection($databaseName, $collectionName, WriteConcern $w
*/
public function selectDatabase($databaseName, WriteConcern $writeConcern = null, ReadPreference $readPreference = null)
{
$writeConcern = $writeConcern ?: \MongoDB\get_manager_write_concern($this->manager);
$readPreference = $readPreference ?: \MongoDB\get_manager_read_preference($this->manager);
$writeConcern = $writeConcern ?: $this->manager->getWriteConcern();
$readPreference = $readPreference ?: $this->manager->getReadPreference();

return new Database($this->manager, $databaseName, $writeConcern, $readPreference);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public function __construct(Manager $manager, $namespace, WriteConcern $writeCon
$this->collectionName = $parts[1];

$this->manager = $manager;
$this->writeConcern = $writeConcern ?: \MongoDB\get_manager_write_concern($this->manager);
$this->readPreference = $readPreference ?: \MongoDB\get_manager_read_preference($this->manager);
$this->writeConcern = $writeConcern ?: $this->manager->getWriteConcern();
$this->readPreference = $readPreference ?: $this->manager->getReadPreference();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public function __construct(Manager $manager, $databaseName, WriteConcern $write

$this->manager = $manager;
$this->databaseName = (string) $databaseName;
$this->writeConcern = $writeConcern ?: \MongoDB\get_manager_write_concern($this->manager);
$this->readPreference = $readPreference ?: \MongoDB\get_manager_read_preference($this->manager);
$this->writeConcern = $writeConcern ?: $this->manager->getWriteConcern();
$this->readPreference = $readPreference ?: $this->manager->getReadPreference();
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/BulkWrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public function __construct($databaseName, $collectionName, array $operations, a
*/
public function execute(Server $server)
{
$bulk = new Bulk($this->options['ordered']);
$bulk = new Bulk(['ordered' => $this->options['ordered']]);
$insertedIds = array();

foreach ($this->operations as $i => $operation) {
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/CreateIndexes.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ private function executeCommand(Server $server)
*/
private function executeLegacy(Server $server)
{
$bulk = new Bulk(true);
$bulk = new Bulk(['ordered' => true]);

foreach ($this->indexes as $index) {
$bulk->insert($index);
Expand Down
2 changes: 1 addition & 1 deletion src/Operation/InsertMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public function __construct($databaseName, $collectionName, array $documents, ar
*/
public function execute(Server $server)
{
$bulk = new Bulk($this->options['ordered']);
$bulk = new Bulk(['ordered' => $this->options['ordered']]);
$insertedIds = array();

foreach ($this->documents as $i => $document) {
Expand Down
67 changes: 0 additions & 67 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@

namespace MongoDB;

use MongoDB\Driver\Manager;
use MongoDB\Driver\ReadPreference;
use MongoDB\Driver\Server;
use MongoDB\Driver\WriteConcern;
use MongoDB\Exception\InvalidArgumentTypeException;
use ReflectionClass;

/**
* Return whether the first key in the document starts with a "$" character.
Expand Down Expand Up @@ -57,69 +53,6 @@ function is_last_pipeline_operator_out(array $pipeline)
return key($lastOp) === '$out';
}

/**
* Returns a ReadPreference corresponding to the Manager's read preference.
*
* @internal
* @todo this function can be removed once PHPC-417 is implemented
* @param Manager $manager
* @return ReadPreference
*/
function get_manager_read_preference(Manager $manager)
{
$rp = $manager->getReadPreference();

if ($rp instanceof ReadPreference) {
return $rp;
}

$args = array(
$rp['mode'],
);

if (isset($rp['tags'])) {
$args[] = $rp['tags'];
}

$rc = new ReflectionClass('MongoDB\Driver\ReadPreference');

return $rc->newInstanceArgs($args);
}

/**
* Returns a WriteConcern corresponding to the Manager's write concern.
*
* @internal
* @todo this function can be removed once PHPC-417 is implemented
* @param Manager $manager
* @return WriteConcern
*/
function get_manager_write_concern(Manager $manager)
{
$wc = $manager->getWriteConcern();

if ($wc instanceof WriteConcern) {
return $wc;
}

$args = array(
isset($wc['w']) ? $wc['w'] : -2,
$wc['wtimeout'],
);

if (isset($wc['journal'])) {
$args[] = $wc['journal'];

if (isset($wc['fsync'])) {
$args[] = $wc['fsync'];
}
}

$rc = new ReflectionClass('MongoDB\Driver\WriteConcern');

return $rc->newInstanceArgs($args);
}

/**
* Generate an index name from a key specification.
*
Expand Down
11 changes: 9 additions & 2 deletions tests/ClientFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace MongoDB\Tests;

use MongoDB\Client;
use MongoDB\Driver\BulkWrite;
use MongoDB\Driver\Command;
use MongoDB\Model\DatabaseInfo;

Expand All @@ -23,7 +24,10 @@ public function setUp()

public function testDropDatabase()
{
$writeResult = $this->manager->executeInsert($this->getNamespace(), array('x' => 1));
$bulkWrite = new BulkWrite();
$bulkWrite->insert(['x' => 1]);

$writeResult = $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite);
$this->assertEquals(1, $writeResult->getInsertedCount());

$commandResult = $this->client->dropDatabase($this->getDatabaseName());
Expand All @@ -33,7 +37,10 @@ public function testDropDatabase()

public function testListDatabases()
{
$writeResult = $this->manager->executeInsert($this->getNamespace(), array('x' => 1));
$bulkWrite = new BulkWrite();
$bulkWrite->insert(['x' => 1]);

$writeResult = $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite);
$this->assertEquals(1, $writeResult->getInsertedCount());

$databases = $this->client->listDatabases();
Expand Down
2 changes: 1 addition & 1 deletion tests/Collection/BulkWriteFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public function testReplaceOneRequiresReplacementDocument()
*/
private function createFixtures($n)
{
$bulkWrite = new BulkWrite(true);
$bulkWrite = new BulkWrite(['ordered' => true]);

for ($i = 1; $i <= $n; $i++) {
$bulkWrite->insert(array(
Expand Down
2 changes: 1 addition & 1 deletion tests/Collection/CollectionFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function testFindOne()
*/
private function createFixtures($n)
{
$bulkWrite = new BulkWrite(true);
$bulkWrite = new BulkWrite(['ordered' => true]);

for ($i = 1; $i <= $n; $i++) {
$bulkWrite->insert(array(
Expand Down
2 changes: 1 addition & 1 deletion tests/Collection/CrudSpec/FunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ abstract class FunctionalTestCase extends BaseFunctionalTestCase
*/
protected function createFixtures($n)
{
$bulkWrite = new BulkWrite(true);
$bulkWrite = new BulkWrite(['ordered' => true]);

for ($i = 1; $i <= $n; $i++) {
$bulkWrite->insert(array(
Expand Down
6 changes: 5 additions & 1 deletion tests/Database/CollectionManagementFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace MongoDB\Tests\Database;

use MongoDB\Driver\BulkWrite;
use MongoDB\Model\CollectionInfo;
use InvalidArgumentException;

Expand Down Expand Up @@ -39,7 +40,10 @@ public function testCreateCollection()

public function testDropCollection()
{
$writeResult = $this->manager->executeInsert($this->getNamespace(), array('x' => 1));
$bulkWrite = new BulkWrite();
$bulkWrite->insert(['x' => 1]);

$writeResult = $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite);
$this->assertEquals(1, $writeResult->getInsertedCount());

$commandResult = $this->database->dropCollection($this->getCollectionName());
Expand Down
6 changes: 5 additions & 1 deletion tests/Database/DatabaseFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace MongoDB\Tests\Database;

use MongoDB\Database;
use MongoDB\Driver\BulkWrite;

/**
* Functional tests for the Database class.
Expand Down Expand Up @@ -39,7 +40,10 @@ public function getGetDatabaseName()

public function testDrop()
{
$writeResult = $this->manager->executeInsert($this->getNamespace(), array('x' => 1));
$bulkWrite = new BulkWrite();
$bulkWrite->insert(['x' => 1]);

$writeResult = $this->manager->executeBulkWrite($this->getNamespace(), $bulkWrite);
$this->assertEquals(1, $writeResult->getInsertedCount());

$commandResult = $this->database->drop();
Expand Down
7 changes: 5 additions & 2 deletions tests/Operation/DropCollectionFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@

use MongoDB\Driver\Server;
use MongoDB\Operation\DropCollection;
use MongoDB\Operation\InsertOne;
use MongoDB\Operation\ListCollections;

class DropCollectionFunctionalTest extends FunctionalTestCase
{
public function testDropExistingCollection()
{
$writeResult = $this->manager->executeInsert($this->getNamespace(), array('x' => 1));
$server = $this->getPrimaryServer();

$insertOne = new InsertOne($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1]);
$writeResult = $insertOne->execute($server);
$this->assertEquals(1, $writeResult->getInsertedCount());

$server = $this->getPrimaryServer();
$operation = new DropCollection($this->getDatabaseName(), $this->getCollectionName());
$operation->execute($server);

Expand Down
7 changes: 5 additions & 2 deletions tests/Operation/DropDatabaseFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@

use MongoDB\Driver\Server;
use MongoDB\Operation\DropDatabase;
use MongoDB\Operation\InsertOne;
use MongoDB\Operation\ListDatabases;

class DropDatabaseFunctionalTest extends FunctionalTestCase
{
public function testDropExistingDatabase()
{
$writeResult = $this->manager->executeInsert($this->getNamespace(), array('x' => 1));
$server = $this->getPrimaryServer();

$insertOne = new InsertOne($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1]);
$writeResult = $insertOne->execute($server);
$this->assertEquals(1, $writeResult->getInsertedCount());

$server = $this->getPrimaryServer();
$operation = new DropDatabase($this->getDatabaseName());
$operation->execute($server);

Expand Down
2 changes: 1 addition & 1 deletion tests/Operation/FindOneFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function provideTypeMapOptionsAndExpectedDocument()
*/
private function createFixtures($n)
{
$bulkWrite = new BulkWrite(true);
$bulkWrite = new BulkWrite(['ordered' => true]);

for ($i = 1; $i <= $n; $i++) {
$bulkWrite->insert([
Expand Down
4 changes: 3 additions & 1 deletion tests/Operation/ListCollectionsFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use MongoDB\Driver\Server;
use MongoDB\Operation\DropDatabase;
use MongoDB\Operation\InsertOne;
use MongoDB\Operation\ListCollections;

class ListCollectionsFunctionalTest extends FunctionalTestCase
Expand All @@ -15,7 +16,8 @@ public function testListCollectionsForNewlyCreatedDatabase()
$operation = new DropDatabase($this->getDatabaseName());
$operation->execute($server);

$writeResult = $this->manager->executeInsert($this->getNamespace(), ['x' => 1]);
$insertOne = new InsertOne($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1]);
$writeResult = $insertOne->execute($server);
$this->assertEquals(1, $writeResult->getInsertedCount());

$operation = new ListCollections($this->getDatabaseName(), ['filter' => ['name' => $this->getCollectionName()]]);
Expand Down
4 changes: 3 additions & 1 deletion tests/Operation/ListIndexesFunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use MongoDB\Driver\Server;
use MongoDB\Operation\DropCollection;
use MongoDB\Operation\InsertOne;
use MongoDB\Operation\ListIndexes;

class ListIndexesFunctionalTest extends FunctionalTestCase
Expand All @@ -15,7 +16,8 @@ public function testListIndexesForNewlyCreatedCollection()
$operation = new DropCollection($this->getDatabaseName(), $this->getCollectionName());
$operation->execute($server);

$writeResult = $this->manager->executeInsert($this->getNamespace(), ['x' => 1]);
$insertOne = new InsertOne($this->getDatabaseName(), $this->getCollectionName(), ['x' => 1]);
$writeResult = $insertOne->execute($server);
$this->assertEquals(1, $writeResult->getInsertedCount());

$operation = new ListIndexes($this->getDatabaseName(), $this->getCollectionName());
Expand Down