Completed
Push — master ( b9f1e5...5ff555 )
by Aimeos
11:02
created

TestHelper::createContext()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 42

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 42
rs 9.248
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
4
class TestHelper
5
{
6
	private static $aimeos;
7
	private static $context = array();
8
9
10
	public static function bootstrap()
11
	{
12
		$aimeos = self::getAimeos();
13
14
		$includepaths = $aimeos->getIncludePaths();
15
		$includepaths[] = get_include_path();
16
		set_include_path( implode( PATH_SEPARATOR, $includepaths ) );
17
	}
18
19
20
	private static function getAimeos()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
21
	{
22
		if( !isset( self::$aimeos ) )
23
		{
24
			require_once 'Bootstrap.php';
25
			spl_autoload_register( 'Aimeos\\Bootstrap::autoload' );
26
27
			self::$aimeos = new \Aimeos\Bootstrap();
28
		}
29
30
		return self::$aimeos;
31
	}
32
33
34
	public static function getContext( $site = 'unittest' )
35
	{
36
		if( !isset( self::$context[$site] ) ) {
37
			self::$context[$site] = self::createContext( $site );
38
		}
39
40
		return clone self::$context[$site];
41
	}
42
43
44
	/**
45
	 * @param string $site
46
	 */
47
	private static function createContext( $site )
48
	{
49
		$ctx = new \Aimeos\MShop\Context\Item\Standard();
50
		$aimeos = self::getAimeos();
51
52
53
		$paths = $aimeos->getConfigPaths();
54
		$paths[] = __DIR__ . DIRECTORY_SEPARATOR . 'config';
55
56
		$conf = new \Aimeos\MW\Config\PHPArray( array(), $paths );
57
		$ctx->setConfig( $conf );
58
59
60
		$dbm = new \Aimeos\MW\DB\Manager\DBAL( $conf );
61
		$ctx->setDatabaseManager( $dbm );
62
63
64
		$logger = new \Aimeos\MW\Logger\File( $site . '.log', \Aimeos\MW\Logger\Base::DEBUG );
65
		$ctx->setLogger( $logger );
66
67
68
		$cache = new \Aimeos\MW\Cache\None();
69
		$ctx->setCache( $cache );
70
71
72
		$i18n = new \Aimeos\MW\Translation\None( 'de' );
73
		$ctx->setI18n( array( 'de' => $i18n ) );
74
75
76
		$session = new \Aimeos\MW\Session\None();
77
		$ctx->setSession( $session );
78
79
80
		$localeManager = \Aimeos\MShop\Locale\Manager\Factory::create( $ctx );
81
		$localeItem = $localeManager->bootstrap( $site, '', '', false );
82
83
		$ctx->setLocale( $localeItem );
84
85
		$ctx->setEditor( 'ai-client-html:lib/custom' );
86
87
		return $ctx;
88
	}
89
}
90