Completed
Push — master ( 82ed2a...577910 )
by Aimeos
14:13
created

TestHelper::bootstrap()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2021
6
 */
7
8
9
class TestHelper
10
{
11
	private static $aimeos;
12
	private static $context = [];
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()
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...
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
		$file = __DIR__ . DIRECTORY_SEPARATOR . 'confdoc.ser';
59
60
		$conf = new \Aimeos\MW\Config\PHPArray( [], $paths );
61
		$conf = new \Aimeos\MW\Config\Decorator\Memory( $conf );
62
		$conf = new \Aimeos\MW\Config\Decorator\Documentor( $conf, $file );
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
		$i18n = new \Aimeos\MW\Translation\None( 'de' );
75
		$ctx->setI18n( array( 'de' => $i18n ) );
76
77
78
		$session = new \Aimeos\MW\Session\None();
79
		$ctx->setSession( $session );
80
81
82
		$localeManager = \Aimeos\MShop\Locale\Manager\Factory::create( $ctx );
83
		$localeItem = $localeManager->bootstrap( $site, '', '', false );
84
85
		$ctx->setLocale( $localeItem );
86
87
		$ctx->setEditor( 'ai-laravel:lib/custom' );
88
89
		return $ctx;
90
	}
91
}
92