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

TestEnvironment   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
c 2
b 0
f 1
lcom 0
cbo 3
dl 0
loc 38
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A newDefault() 0 3 1
A __construct() 0 7 1
A getFactory() 0 3 1
A newConnectionDetails() 0 16 2
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