public function testSystemConfigDb() { $xml = '<config> <database> <connections> <connection> <name>testdb</name> <username>peter</username> </connection> </connections> </database> </config>'; $config = new SystemConfig(); $connection = new Connection(); $connection->setUsername('peter'); $connection->setType('mysql'); $connection->setName('testdb'); $database = new Database(); $config->setDatabase($database); $config->getDatabase()->addConnection($connection); $output = $config->toXml(); $this->assertEquals($xml, $output); $reverse = new SystemConfig($xml); $this->assertInternalType('array', $reverse->getDatabase()->getConnections()); $this->assertInstanceOf('\\Jarves\\Configuration\\Connection', $reverse->getDatabase()->getConnections()[0]); $this->assertEquals('mysql', $reverse->getDatabase()->getConnections()[0]->getType()); $this->assertEquals('peter', $reverse->getDatabase()->getConnections()[0]->getUsername()); $this->assertEquals('testdb', $reverse->getDatabase()->getConnections()[0]->getName()); $this->assertEquals($xml, $reverse->toXml()); }
public function getManagerConfig(Connection $connection) { $config = []; $config['dsn'] = $connection->getDsn(); $config['user'] = (string) $connection->getUsername(); $config['password'] = (string) $connection->getPassword(); $config['options']['ATTR_PERSISTENT'] = (bool) $connection->getPersistent(); $config['settings']['charset'] = $connection->getCharset(); return $config; }