public getCollection ( string $name ) : |
||
$name | string | name of collection |
Résultat |
public function testGetOptions() { // define array of collections $this->database->map(array('collection1' => array('someOption' => 'someValue'))); $options = $this->database->getCollection('collection1')->getOptions(); $this->assertArrayHasKey('someOption', $options); $this->assertEquals($options['someOption'], 'someValue'); }
/** * @expectedException \Sokil\Mongo\Exception * @expectedExceptionMessage Class \ThisClassIsNotExists not found while map collection name to class */ public function testGetCollection_UnexistedClassInMapping() { $this->database->resetMapping(); $this->database->map(array('collection' => '\\ThisClassIsNotExists')); $this->database->getCollection('collection'); }
/** * @expectedException \Sokil\Mongo\Exception * @expectedExceptionMessage Wrong definition passed for collection acmeCollection */ public function testMap_InvalidDefinitionVariableType() { $this->database->resetMapping(); $this->database->map(array('acmeCollection' => 42)); $this->database->getCollection('collection'); }
public function testSetServerTimeoutInMapping() { $this->database->map('col', array('cursorServerTimeout' => 42)); $cursor = $this->database->getCollection('col')->find(); $this->assertEquals(42, $cursor->getOption('serverTimeout')); }
/** * @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')))); }