TestEnvironment::getFactory()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
declare( strict_types = 1 );
4
5
namespace WMDE\Fundraising\Store\Tests;
6
7
use Doctrine\DBAL\DriverManager;
8
use WMDE\Fundraising\Store\Factory;
9
10
/**
11
 * @licence GNU GPL v2+
12
 * @author Jeroen De Dauw < [email protected] >
13
 * @author Jonas Kress
14
 */
15
class TestEnvironment {
16
17
	public static function newDefault() {
18
		return new self();
19
	}
20
21
	private $factory;
22
23
	public function __construct() {
24
		$this->factory = new Factory( DriverManager::getConnection(
25
			$this->newConnectionDetails()
26
		) );
27
28
		try {
29
			$this->factory->newInstaller()->uninstall();
30
		}
31
		catch ( \Exception $ex ) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
32
		}
33
34
		$this->factory->newInstaller()->install();
35
	}
36
37
	public function getFactory() {
38
		return $this->factory;
39
	}
40
41
	private function newConnectionDetails() {
42
		if ( getenv( 'DB' ) === 'mysql' ) {
43
			return [
44
				'driver' => 'pdo_mysql',
45
				'user' => 'root',
46
				'password' => '',
47
				'dbname' => 'spenden',
48
				'host' => 'localhost',
49
			];
50
		}
51
52
		return [
53
			'driver' => 'pdo_sqlite',
54
			'memory' => true,
55
		];
56
	}
57
58
	public function getDatabaseName() {
59
		if ( getenv( 'DB' ) === 'mysql' ) {
60
			return 'spenden';
61
		}
62
63
		return 'public';
64
	}
65
66
}
67