summaryrefslogtreecommitdiffstats
path: root/tests/mocks/database/db.php
blob: d7a6351a0d2cd91a726b437049080ac6bfaec8f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php

class Mock_Database_DB {

	private $config = array();
	
	/**
	 * Prepare database configuration skeleton
	 *
	 * @param  array 	DB configuration to set
	 * @return void
	 */
	public function __construct($config = array())
	{
		include_once(BASEPATH.'database/DB.php');

		$this->config = $config;
	}

	public function set_config($group = 'default')
	{
		if ( ! isset($this->config[$group]))
		{
			throw new InvalidArgumentException('Group '.$group.' not exists');
		}

		if ( ! empty($this->config[$group]['dsn']))
		{
			$dsn = $this->config[$group]['dsn'];
		}
		else
		{
			$config = $this->config[$group];
			$dsn = $config['dbdriver'].'://'.$config['username'].':'.$config['password']
			       .'@'.$config['hostname'].'/'.$config['database'];

		}

		$params = array_slice($this->config[$group], 6);

		return $dsn.http_build_query($params);
	}
}