/** * @expectedException \Sokil\Mongo\Exception * @expectedExceptionMessage Error deleting file: some_error: Some error message */ public function testDeleteFileById_WithAcknowledgedWriteConcern() { $mongoGridFsMock = $this->getMock('\\MongoGridFS', array('delete'), array($this->database->getMongoDB(), 'images')); $mongoGridFsMock->expects($this->once())->method('delete')->will($this->returnValue(array('ok' => (double) 0, 'err' => 'some_error', 'errmsg' => 'Some error message'))); $gridFS = new GridFS($this->database, $mongoGridFsMock); $id = $gridFS->storeBytes('data'); $gridFS->deleteFileById($id); }
public function testIsVersioningEnabled() { // set by property $this->database->map('col1', '\\Sokil\\Mongo\\CollectionWithVersioningMock'); $this->assertTrue($this->database->col1->isVersioningEnabled()); // set by map definition $this->database->map('col2', array('versioning' => true)); $this->assertTrue($this->database->col2->isVersioningEnabled()); // set by map definition $this->database->map('col3', array('versioning' => false)); $this->assertFalse($this->database->col3->isVersioningEnabled()); }
public function explainAggregate($pipeline) { if (version_compare($this->getDatabase()->getClient()->getDbVersion(), '2.6.0', '<')) { throw new Exception('Explain of aggregation implemented only from 2.6.0'); } if ($pipeline instanceof Pipeline) { $pipeline = $pipeline->toArray(); } elseif (!is_array($pipeline)) { throw new Exception('Wrong pipeline specified'); } // aggregate return $this->_database->executeCommand(array('aggregate' => $this->getName(), 'pipeline' => $pipeline, 'explain' => true)); }
public function testDequeueFromNotExistedCollection() { $queue = $this->database->getQueue('some_strange_unexisted_channel'); $this->assertNull($queue->dequeue()); }
public function testSetMajorityWriteConcern() { $this->database->setMajorityWriteConcern(13000); $this->assertEquals(array('w' => 'majority', 'wtimeout' => 13000), $this->database->getWriteConcern()); }
/** * * @param string $name database name * @return \Sokil\Mongo\Database */ public function getDatabase($name = null) { if (!$name) { $name = $this->getCurrentDatabaseName(); } if (!isset($this->databasePool[$name])) { // init db $database = new Database($this, $name); if (isset($this->_mapping[$name])) { $database->map($this->_mapping[$name]); } // configure db $this->databasePool[$name] = $database; } return $this->databasePool[$name]; }
public function testSetServerTimeoutInMapping() { $this->database->map('col', array('cursorServerTimeout' => 42)); $cursor = $this->database->getCollection('col')->find(); $this->assertEquals(42, $cursor->getOption('serverTimeout')); }
public function setUp() { $client = new Client(); $this->database = $client->getDatabase('test'); $this->gridFs = $this->database->getGridFs('images'); }
/** * @expectedException \Sokil\Mongo\Exception * @expectedExceptionMessage Aggregate error: some_error */ public function testAggregate_ServerSideError() { $mongoDatabaseMock = $this->getMock('\\MongoDB', array('command'), array($this->collection->getDatabase()->getClient()->getMongoClient(), 'test')); $mongoDatabaseMock->expects($this->once())->method('command')->will($this->returnValue(array('ok' => (double) 0, 'errmsg' => 'some_error', 'code' => 1785342))); $database = new Database($this->collection->getDatabase()->getClient(), $mongoDatabaseMock); $database->getCollection('phpmongo_test_collection')->aggregate(array(array('$match' => array('field' => 'value')))); }
public function setUp() { $client = new Client(getenv('PHPMONGO_DSN') ? getenv('PHPMONGO_DSN') : null); $this->database = $client->getDatabase('test'); $this->gridFs = $this->database->getGridFs('images'); }