public function testConnections() { $connections = array('local' => new Connection('localhost', $this->dbName . '_local'), 'global' => new Connection('localhost', $this->dbName . '_global'), 'extra' => new Connection('localhost', $this->dbName . '_extra')); // hasConnection, setConnection, getConnection $mongator = new Mongator($this->metadataFactory); $this->assertFalse($mongator->hasConnection('local')); $mongator->setConnection('local', $connections['local']); $this->assertTrue($mongator->hasConnection('local')); $mongator->setConnection('extra', $connections['extra']); $this->assertSame($connections['local'], $mongator->getConnection('local')); $this->assertSame($connections['extra'], $mongator->getConnection('extra')); // setConnections, getConnections $mongator = new Mongator($this->metadataFactory); $mongator->setConnection('extra', $connections['extra']); $mongator->setConnections($setConnections = array('local' => $connections['local'], 'global' => $connections['global'])); $this->assertEquals($setConnections, $mongator->getConnections()); // removeConnection $mongator = new Mongator($this->metadataFactory); $mongator->setConnections($connections); $mongator->removeConnection('local'); $this->assertSame(array('global' => $connections['global'], 'extra' => $connections['extra']), $mongator->getConnections()); // clearConnections $mongator = new Mongator($this->metadataFactory); $mongator->setConnections($connections); $mongator->clearConnections(); $this->assertSame(array(), $mongator->getConnections()); // defaultConnection $mongator = new Mongator($this->metadataFactory); $mongator->setConnections($connections); $mongator->setDefaultConnectionName('global'); $this->assertSame($connections['global'], $mongator->getDefaultConnection()); }
public function testGetConnection() { $connections = array('local' => new Connection($this->server, $this->dbName . '_local'), 'global' => new Connection($this->server, $this->dbName . '_global')); $mongator = new Mongator($this->metadataFactory, $this->cache); $mongator->setConnections($connections); $mongator->setDefaultConnectionName('local'); $this->assertSame($connections['local'], $mongator->getRepository('Model\\Article')->getConnection()); $this->assertSame($connections['global'], $mongator->getRepository('Model\\ConnectionGlobal')->getConnection()); }