TestHelper   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Importance

Changes 7
Bugs 0 Features 0
Metric Value
wmc 6
eloc 33
dl 0
loc 77
rs 10
c 7
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A bootstrap() 0 7 1
A createContext() 0 33 1
A getAimeos() 0 12 2
A getContext() 0 7 2
1
<?php
2
3
/**
4
 * @license LGPLv3, http://www.gnu.org/licenses/lgpl.html
5
 * @copyright Metaways Infosystems GmbH, 2013
6
 * @copyright Aimeos (aimeos.org), 2015-2018
7
 */
8
9
class TestHelper
10
{
11
	private static $aimeos;
12
	private static $context = [];
13
14
15
	public static function bootstrap()
16
	{
17
		$mshop = self::getAimeos();
18
19
		$includepaths = $mshop->getIncludePaths();
20
		$includepaths[] = get_include_path();
21
		set_include_path( implode( PATH_SEPARATOR, $includepaths ) );
22
	}
23
24
25
	public static function getContext( $site = 'unittest' )
26
	{
27
		if( !isset( self::$context[$site] ) ) {
28
			self::$context[$site] = self::createContext( $site );
29
		}
30
31
		return clone self::$context[$site];
32
	}
33
34
35
	private static function getAimeos()
36
	{
37
		if( !isset( self::$aimeos ) )
38
		{
39
			require_once 'Bootstrap.php';
40
			spl_autoload_register( 'Aimeos\\Bootstrap::autoload' );
41
42
			$extdir = dirname( dirname( dirname( __DIR__ ) ) );
43
			self::$aimeos = new \Aimeos\Bootstrap( array( $extdir ), false );
44
		}
45
46
		return self::$aimeos;
47
	}
48
49
50
	/**
51
	 * @param string $site
52
	 */
53
	private static function createContext( $site )
54
	{
55
		$ctx = new \Aimeos\MShop\Context\Item\Standard();
56
		$mshop = self::getAimeos();
57
58
59
		$paths = $mshop->getConfigPaths( 'mysql' );
60
		$paths[] = __DIR__ . DIRECTORY_SEPARATOR . 'config';
61
62
		$conf = new \Aimeos\MW\Config\PHPArray( [], $paths );
63
		$ctx->setConfig( $conf );
64
65
66
		$dbm = new \Aimeos\MW\DB\Manager\PDO( $conf );
67
		$ctx->setDatabaseManager( $dbm );
68
69
70
		$logger = new \Aimeos\MW\Logger\File( $site . '.log', \Aimeos\MW\Logger\Base::DEBUG );
71
		$ctx->setLogger( $logger );
72
73
74
		$session = new \Aimeos\MW\Session\None();
75
		$ctx->setSession( $session );
76
77
78
		$localeManager = \Aimeos\MShop\Locale\Manager\Factory::create( $ctx );
79
		$localeItem = $localeManager->bootstrap( $site, '', '', false );
80
81
		$ctx->setLocale( $localeItem );
82
83
		$ctx->setEditor( 'ai-container:lib/custom' );
84
85
		return $ctx;
86
	}
87
}
88