Passed
Push — master ( f381ab...b62f3e )
by Aimeos
02:34
created

TestHelper::getConnection()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
rs 10
cc 2
nc 2
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2022
6
 */
7
8
9
class TestHelper
10
{
11
	private static $config;
12
	private static $dbm;
13
14
15
	/**
16
	 * Returns the configuration object
17
	 *
18
	 * @return \Aimeos\Base\Config\Iface Configuration object
19
	 */
20
	public static function getConfig() : \Aimeos\Base\Config\Iface
21
	{
22
		if( !isset( self::$config ) ) {
23
			self::$config = self::createConfig();
24
		}
25
26
		return self::$config;
27
	}
28
29
30
	/**
31
	 * Returns the database connection object
32
	 *
33
	 * @return \Aimeos\Base\DB\Connection\Iface Database connection object
34
	 */
35
	public static function getConnection() : \Aimeos\Base\DB\Connection\Iface
36
	{
37
		if( !isset( self::$dbm ) ) {
38
			self::$dbm = new \Aimeos\Base\DB\Manager\Standard( self::getConfig()->get( 'resource', [] ), 'DBAL' );
39
		}
40
41
		return self::$dbm->get();
42
	}
43
44
45
	/**
46
	 * Creates a new configuration object
47
	 *
48
	 * @return \Aimeos\Base\Config\Iface Configuration object
49
	 */
50
	private static function createConfig() : \Aimeos\Base\Config\Iface
51
	{
52
		$path = dirname( __DIR__ ) . DIRECTORY_SEPARATOR . 'config';
53
		$file = __DIR__ . DIRECTORY_SEPARATOR . 'confdoc.ser';
54
55
		$object = new \Aimeos\Base\Config\PHPArray( [], $path );
56
		$object = new \Aimeos\Base\Config\Decorator\Documentor( $object, $file );
57
58
		return $object;
59
	}
60
}
61