getCollection() public method

public getCollection ( string $name ) : Collection
$name string name of collection
return Collection
Example #1
0
 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');
 }
Example #2
0
 /**
  * @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');
 }
Example #3
0
 /**
  * @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');
 }
Example #4
0
 public function testSetServerTimeoutInMapping()
 {
     $this->database->map('col', array('cursorServerTimeout' => 42));
     $cursor = $this->database->getCollection('col')->find();
     $this->assertEquals(42, $cursor->getOption('serverTimeout'));
 }
Example #5
0
 /**
  * @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'))));
 }