Exemplo n.º 1
0
 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
     $mandango = new Mandango($this->metadataFactory, $this->cache);
     $this->assertFalse($mandango->hasConnection('local'));
     $mandango->setConnection('local', $connections['local']);
     $this->assertTrue($mandango->hasConnection('local'));
     $mandango->setConnection('extra', $connections['extra']);
     $this->assertSame($connections['local'], $mandango->getConnection('local'));
     $this->assertSame($connections['extra'], $mandango->getConnection('extra'));
     // setConnections, getConnections
     $mandango = new Mandango($this->metadataFactory, $this->cache);
     $mandango->setConnection('extra', $connections['extra']);
     $mandango->setConnections($setConnections = array('local' => $connections['local'], 'global' => $connections['global']));
     $this->assertEquals($setConnections, $mandango->getConnections());
     // removeConnection
     $mandango = new Mandango($this->metadataFactory, $this->cache);
     $mandango->setConnections($connections);
     $mandango->removeConnection('local');
     $this->assertSame(array('global' => $connections['global'], 'extra' => $connections['extra']), $mandango->getConnections());
     // clearConnections
     $mandango = new Mandango($this->metadataFactory, $this->cache);
     $mandango->setConnections($connections);
     $mandango->clearConnections();
     $this->assertSame(array(), $mandango->getConnections());
     // defaultConnection
     $mandango = new Mandango($this->metadataFactory, $this->cache);
     $mandango->setConnections($connections);
     $mandango->setDefaultConnectionName('global');
     $this->assertSame($connections['global'], $mandango->getDefaultConnection());
 }