This repository has been archived by the owner on Jul 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
TestHelper.php
83 lines (58 loc) · 1.75 KB
/
TestHelper.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<?php
/**
* @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
* @copyright Aimeos (aimeos.org), 2014-2018
*/
class TestHelper
{
private static $aimeos;
private static $context = [];
public static function bootstrap()
{
$mshop = self::getAimeos();
$includepaths = $mshop->getIncludePaths();
$includepaths[] = get_include_path();
set_include_path( implode( PATH_SEPARATOR, $includepaths ) );
}
public static function getContext( $site = 'unittest' )
{
if( !isset( self::$context[$site] ) ) {
self::$context[$site] = self::createContext( $site );
}
return clone self::$context[$site];
}
private static function getAimeos()
{
if( !isset( self::$aimeos ) )
{
require_once 'Bootstrap.php';
spl_autoload_register( 'Aimeos\\Bootstrap::autoload' );
$extdir = dirname( dirname( dirname( dirname( __FILE__ ) ) ) );
self::$aimeos = new \Aimeos\Bootstrap( array( $extdir ), false );
}
return self::$aimeos;
}
/**
* Creates a new context item.
*
* @param string $site Unique site code
* @return \\Aimeos\MShop\Context\Item\Iface Context object
*/
private static function createContext( $site )
{
$ctx = new \Aimeos\MShop\Context\Item\Standard();
$mshop = self::getAimeos();
$paths = $mshop->getConfigPaths( 'mysql' );
$paths[] = __DIR__ . DIRECTORY_SEPARATOR . 'config';
$conf = new \Aimeos\MW\Config\PHPArray( [], $paths );
$ctx->setConfig( $conf );
$dbm = new \Aimeos\MW\DB\Manager\PDO( $conf );
$ctx->setDatabaseManager( $dbm );
$logger = new \Aimeos\MW\Logger\File( $site . '.log', \Aimeos\MW\Logger\Base::DEBUG );
$ctx->setLogger( $logger );
$session = new \Aimeos\MW\Session\None();
$ctx->setSession( $session );
$ctx->setEditor( 'ai-flow:unittest' );
return $ctx;
}
}