TestHelper::bootstrap()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 8
rs 9.4285
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
3
4
/**
5
 * @copyright Metaways Infosystems GmbH, 2011
6
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
7
 * @copyright Aimeos (aimeos.org), 2015
8
 */
9
class TestHelper
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
10
{
11
	private static $aimeos;
12
	private static $context = array();
13
14
15
	public static function bootstrap()
16
	{
17
		$aimeos = self::getAimeos();
18
19
		$includepaths = $aimeos->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
	private static function createContext( $site )
51
	{
52
		$ctx = new \Aimeos\MShop\Context\Item\Standard();
53
		$aimeos = self::getAimeos();
54
55
56
		$paths = $aimeos->getConfigPaths( 'mysql' );
57
		$paths[] = __DIR__ . DIRECTORY_SEPARATOR . 'config';
58
59
		$conf = new \Aimeos\MW\Config\PHPArray( array(), $paths );
60
		$ctx->setConfig( $conf );
61
62
63
		$dbm = new \Aimeos\MW\DB\Manager\PDO( $conf );
64
		$ctx->setDatabaseManager( $dbm );
65
66
67
		$logger = new \Aimeos\MW\Logger\File( $site . '.log', \Aimeos\MW\Logger\Base::DEBUG );
68
		$ctx->setLogger( $logger );
69
70
71
		$cache = new \Aimeos\MW\Cache\None();
72
		$ctx->setCache( $cache );
73
74
75
		$i18n = new \Aimeos\MW\Translation\None( 'de' );
76
		$ctx->setI18n( array( 'de' => $i18n ) );
77
78
79
		$session = new \Aimeos\MW\Session\None();
80
		$ctx->setSession( $session );
81
82
83
		$localeManager = \Aimeos\MShop\Locale\Manager\Factory::createManager( $ctx );
84
		$localeItem = $localeManager->bootstrap( $site, '', '', false );
85
86
		$ctx->setLocale( $localeItem );
87
88
		$ctx->setEditor( 'ai-mqueue:unittest' );
89
90
		return $ctx;
91
	}
92
}
93