Completed
Pull Request — master (#60)
by Jeroen De
05:23
created

TestEnvironment::newConnectionDetails()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 16
rs 9.4285
cc 2
eloc 11
nc 2
nop 0
1
<?php
2
3
namespace WMDE\Fundraising\Store\Tests;
4
5
use Doctrine\DBAL\DriverManager;
6
use WMDE\Fundraising\Store\Factory;
7
8
/**
9
 * @licence GNU GPL v2+
10
 * @author Jeroen De Dauw < [email protected] >
11
 * @author Jonas Kress
12
 */
13
class TestEnvironment {
14
15
	public static function newDefault() {
16
		return new self();
17
	}
18
19
	private $factory;
20
21
	public function __construct() {
22
		$this->factory = new Factory( DriverManager::getConnection(
23
			$this->newConnectionDetails()
24
		) );
25
26
		$this->factory->newInstaller()->install();
27
	}
28
29
	public function getFactory() {
30
		return $this->factory;
31
	}
32
33
	private function newConnectionDetails() {
34
		if ( getenv( 'DB' ) === 'mysql' ) {
35
			return [
36
				'driver' => 'pdo_mysql',
37
				'user' => 'root',
38
				'password' => '',
39
				'dbname' => 'spenden',
40
				'host' => 'localhost',
41
			];
42
		}
43
44
		return [
45
			'driver' => 'pdo_sqlite',
46
			'memory' => true,
47
		];
48
	}
49
50
}
51