Completed
Pull Request — master (#60)
by Jeroen De
02:17
created

TestEnvironment::getDatabaseName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 7
rs 9.4285
cc 2
eloc 4
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
		try {
27
			$this->factory->newInstaller()->uninstall();
28
		}
29
		catch ( \Exception $ex ) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
30
		}
31
32
		$this->factory->newInstaller()->install();
33
	}
34
35
	public function getFactory() {
36
		return $this->factory;
37
	}
38
39
	private function newConnectionDetails() {
40
		if ( getenv( 'DB' ) === 'mysql' ) {
41
			return [
42
				'driver' => 'pdo_mysql',
43
				'user' => 'root',
44
				'password' => '',
45
				'dbname' => 'spenden',
46
				'host' => 'localhost',
47
			];
48
		}
49
50
		return [
51
			'driver' => 'pdo_sqlite',
52
			'memory' => true,
53
		];
54
	}
55
56
	public function getDatabaseName() {
57
		if ( getenv( 'DB' ) === 'mysql' ) {
58
			return 'spenden';
59
		}
60
61
		return 'public';
62
	}
63
64
}
65