Passed
Push — master ( cda682...7c7c79 )
by Aimeos
29:36 queued 21:19
created

lib/custom/tests/TestHelper.php (1 issue)

1
<?php
2
3
4
/**
5
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
6
 * @copyright Metaways Infosystems GmbH, 2011
7
 * @copyright Aimeos (aimeos.org), 2015-2022
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 context( $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
		$ctx->setEditor( 'ai-filesystem:lib/custom' );
54
55
		$paths = $aimeos->getConfigPaths( 'mysql' );
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $aimeos seems to be never defined.
Loading history...
56
		$paths[] = __DIR__ . DIRECTORY_SEPARATOR . 'config';
57
58
		$conf = new \Aimeos\MW\Config\PHPArray( [], $paths );
59
		$ctx->setConfig( $conf );
60
61
		return $ctx;
62
	}
63
}
64