TestHelper::getAimeos()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 11
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2014-2025
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 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
	public static function getAimeos()
36
	{
37
		if( !isset( self::$aimeos ) )
38
		{
39
			require_once 'Bootstrap.php';
40
			spl_autoload_register( 'Aimeos\\Bootstrap::autoload' );
41
42
			self::$aimeos = new \Aimeos\Bootstrap();
43
		}
44
45
		return self::$aimeos;
46
	}
47
48
49
	private static function createContext( $site )
50
	{
51
		$ctx = new \Aimeos\MShop\Context();
52
		$aimeos = self::getAimeos();
53
54
55
		$paths = $aimeos->getConfigPaths();
56
		$paths[] = __DIR__ . DIRECTORY_SEPARATOR . 'config';
57
		$file = __DIR__ . DIRECTORY_SEPARATOR . 'confdoc.ser';
58
59
		$conf = new \Aimeos\Base\Config\PHPArray( [], $paths );
60
		$conf = new \Aimeos\Base\Config\Decorator\Memory( $conf );
61
		$conf = new \Aimeos\Base\Config\Decorator\Documentor( $conf, $file );
62
		$ctx->setConfig( $conf );
63
64
65
		$dbm = new \Aimeos\Base\DB\Manager\Standard( $conf->get( 'resource', [] ), 'PDO' );
66
		$ctx->setDatabaseManager( $dbm );
67
68
69
		$logger = new \Aimeos\Base\Logger\File( $site . '.log', \Aimeos\Base\Logger\Iface::DEBUG );
70
		$ctx->setLogger( $logger );
71
72
73
		$i18n = new \Aimeos\Base\Translation\None( 'de' );
74
		$ctx->setI18n( array( 'de' => $i18n ) );
75
76
77
		$session = new \Aimeos\Base\Session\None();
78
		$ctx->setSession( $session );
79
80
81
		$localeManager = \Aimeos\MShop::create( $ctx, 'locale' );
82
		$localeItem = $localeManager->bootstrap( $site, '', '', false );
0 ignored issues
show
Bug introduced by
The method bootstrap() does not exist on Aimeos\MShop\Common\Manager\Iface. It seems like you code against a sub-type of said class. However, the method does not exist in Aimeos\MShop\Common\Manager\Decorator\Iface or Aimeos\MShop\Order\Manag...rvice\Transaction\Iface or Aimeos\MShop\Price\Manager\Iface or Aimeos\MShop\Type\Manager\Iface or Aimeos\MShop\Order\Manager\Service\Iface or Aimeos\MShop\Review\Manager\Iface or Aimeos\MShop\Coupon\Manager\Code\Iface or Aimeos\MShop\Product\Manager\Iface or Aimeos\MShop\Supplier\Manager\Iface or Aimeos\MShop\Common\Manager\Property\Iface or Aimeos\MShop\Customer\Manager\Property\Iface or Aimeos\MShop\Locale\Manager\Currency\Iface or Aimeos\MShop\Tag\Manager\Iface or Aimeos\MShop\Coupon\Manager\Iface or Aimeos\MShop\Attribute\Manager\Iface or Aimeos\MShop\Common\Manager\Lists\Iface or Aimeos\MShop\Order\Manager\Address\Iface or Aimeos\MShop\Order\Manager\Product\Attribute\Iface or Aimeos\MShop\Order\Manager\Iface or Aimeos\MShop\Customer\Manager\Iface or Aimeos\MShop\Media\Manager\Iface or Aimeos\MShop\Order\Manager\Coupon\Iface or Aimeos\MShop\Plugin\Manager\Iface or Aimeos\MShop\Group\Manager\Iface or Aimeos\MShop\Catalog\Manager\Iface or Aimeos\MShop\Locale\Manager\Site\Iface or Aimeos\MShop\Order\Manager\Service\Attribute\Iface or Aimeos\MShop\Text\Manager\Iface or Aimeos\MAdmin\Job\Manager\Iface or Aimeos\MShop\Order\Manager\Status\Iface or Aimeos\MShop\Rule\Manager\Iface or Aimeos\MShop\Common\Manager\Address\Iface or Aimeos\MShop\Basket\Manager\Iface or Aimeos\MShop\Stock\Manager\Iface or Aimeos\MShop\Attribute\Manager\Property\Iface or Aimeos\MShop\Subscription\Manager\Iface or Aimeos\MShop\Product\Manager\Property\Iface or Aimeos\MShop\Locale\Manager\Language\Iface or Aimeos\MShop\Media\Manager\Property\Iface or Aimeos\MShop\Service\Manager\Iface or Aimeos\MAdmin\Log\Manager\Iface or Aimeos\MAdmin\Cache\Manager\Iface or Aimeos\MShop\Order\Manager\Product\Iface or Aimeos\MShop\Price\Manager\Property\Iface or Aimeos\MShop\Service\Manager\Lists\Type\Iface or Aimeos\MShop\Attribute\Manager\Type\Iface or Aimeos\MShop\Price\Manager\Lists\Type\Iface or Aimeos\MShop\Media\Manager\Type\Iface or Aimeos\MShop\Price\Manager\Property\Type\Iface or Aimeos\MShop\Supplier\Manager\Lists\Type\Iface or Aimeos\MShop\Tag\Manager\Type\Iface or Aimeos\MShop\Price\Manager\Type\Iface or Aimeos\MShop\Media\Manager\Lists\Type\Iface or Aimeos\MShop\Attribute\Manager\Property\Type\Iface or Aimeos\MShop\Service\Manager\Type\Iface or Aimeos\MShop\Customer\Manager\Property\Type\Iface or Aimeos\MShop\Rule\Manager\Type\Iface or Aimeos\MShop\Customer\Manager\Lists\Type\Iface or Aimeos\MShop\Product\Manager\Property\Type\Iface or Aimeos\MShop\Product\Manager\Type\Iface or Aimeos\MShop\Stock\Manager\Type\Iface or Aimeos\MShop\Product\Manager\Lists\Type\Iface or Aimeos\MShop\Text\Manager\Lists\Type\Iface or Aimeos\MShop\Text\Manager\Type\Iface or Aimeos\MShop\Plugin\Manager\Type\Iface or Aimeos\MShop\Media\Manager\Property\Type\Iface or Aimeos\MShop\Attribute\Manager\Lists\Type\Iface or Aimeos\MShop\Catalog\Manager\Lists\Type\Iface or Aimeos\MShop\Price\Manager\Lists\Iface or Aimeos\MShop\Service\Manager\Lists\Iface or Aimeos\MShop\Text\Manager\Lists\Iface or Aimeos\MShop\Catalog\Manager\Lists\Iface or Aimeos\MShop\Product\Manager\Lists\Iface or Aimeos\MShop\Attribute\Manager\Lists\Iface or Aimeos\MShop\Media\Manager\Lists\Iface or Aimeos\MShop\Supplier\Manager\Lists\Iface or Aimeos\MShop\Customer\Manager\Lists\Iface or Aimeos\MShop\Supplier\Manager\Address\Iface or Aimeos\MShop\Customer\Manager\Address\Iface. Are you sure you never get one of those? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

82
		/** @scrutinizer ignore-call */ 
83
  $localeItem = $localeManager->bootstrap( $site, '', '', false );
Loading history...
83
		$ctx->setLocale( $localeItem );
84
85
86
		return $ctx->setEditor( 'ai-symfony' );
87
	}
88
}
89