Commit 303de406 authored by Jeremy Mikola's avatar Jeremy Mikola

Merge pull request #42

parents 6693f5f1 66189d6c
......@@ -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
......
......@@ -75,8 +75,8 @@ class Client
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);
}
......@@ -94,8 +94,8 @@ class Client
*/
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);
}
......
......@@ -66,8 +66,8 @@ class Collection
$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();
}
/**
......
......@@ -44,8 +44,8 @@ class Database
$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();
}
/**
......
......@@ -207,7 +207,7 @@ class BulkWrite implements Executable
*/
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) {
......
......@@ -107,7 +107,7 @@ class CreateIndexes implements Executable
*/
private function executeLegacy(Server $server)
{
$bulk = new Bulk(true);
$bulk = new Bulk(['ordered' => true]);
foreach ($this->indexes as $index) {
$bulk->insert($index);
......
......@@ -87,7 +87,7 @@ class InsertMany implements Executable
*/
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) {
......
......@@ -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.
......@@ -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.
*
......
......@@ -3,6 +3,7 @@
namespace MongoDB\Tests;
use MongoDB\Client;
use MongoDB\Driver\BulkWrite;
use MongoDB\Driver\Command;
use MongoDB\Model\DatabaseInfo;
......@@ -23,7 +24,10 @@ class ClientFunctionalTest extends FunctionalTestCase
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());
......@@ -33,7 +37,10 @@ class ClientFunctionalTest extends FunctionalTestCase
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();
......
......@@ -202,7 +202,7 @@ class BulkWriteFunctionalTest extends FunctionalTestCase
*/
private function createFixtures($n)
{
$bulkWrite = new BulkWrite(true);
$bulkWrite = new BulkWrite(['ordered' => true]);
for ($i = 1; $i <= $n; $i++) {
$bulkWrite->insert(array(
......
......@@ -83,7 +83,7 @@ class CollectionFunctionalTest extends FunctionalTestCase
*/
private function createFixtures($n)
{
$bulkWrite = new BulkWrite(true);
$bulkWrite = new BulkWrite(['ordered' => true]);
for ($i = 1; $i <= $n; $i++) {
$bulkWrite->insert(array(
......
......@@ -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(
......
......@@ -2,6 +2,7 @@
namespace MongoDB\Tests\Database;
use MongoDB\Driver\BulkWrite;
use MongoDB\Model\CollectionInfo;
use InvalidArgumentException;
......@@ -39,7 +40,10 @@ class CollectionManagementFunctionalTest extends FunctionalTestCase
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());
......
......@@ -3,6 +3,7 @@
namespace MongoDB\Tests\Database;
use MongoDB\Database;
use MongoDB\Driver\BulkWrite;
/**
* Functional tests for the Database class.
......@@ -39,7 +40,10 @@ class DatabaseFunctionalTest extends FunctionalTestCase
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();
......
......@@ -4,16 +4,19 @@ namespace MongoDB\Tests\Operation;
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);
......
......@@ -4,16 +4,19 @@ namespace MongoDB\Tests\Operation;
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);
......
......@@ -45,7 +45,7 @@ class FindOneFunctionalTest extends FunctionalTestCase
*/
private function createFixtures($n)
{
$bulkWrite = new BulkWrite(true);
$bulkWrite = new BulkWrite(['ordered' => true]);
for ($i = 1; $i <= $n; $i++) {
$bulkWrite->insert([
......
......@@ -4,6 +4,7 @@ namespace MongoDB\Tests\Operation;
use MongoDB\Driver\Server;
use MongoDB\Operation\DropDatabase;
use MongoDB\Operation\InsertOne;
use MongoDB\Operation\ListCollections;
class ListCollectionsFunctionalTest extends FunctionalTestCase
......@@ -15,7 +16,8 @@ class ListCollectionsFunctionalTest extends FunctionalTestCase
$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()]]);
......
......@@ -4,6 +4,7 @@ namespace MongoDB\Tests\Operation;
use MongoDB\Driver\Server;
use MongoDB\Operation\DropCollection;
use MongoDB\Operation\InsertOne;
use MongoDB\Operation\ListIndexes;
class ListIndexesFunctionalTest extends FunctionalTestCase
......@@ -15,7 +16,8 @@ class ListIndexesFunctionalTest extends FunctionalTestCase
$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());
......
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