Passed
Push — master ( 2eaaad...ad5f8f )
by Aimeos
15:24 queued 12:30
created

TestHelper::bootstrap()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
nc 1
nop 0
dl 0
loc 7
c 1
b 0
f 0
cc 1
rs 10
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()
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
	public static function getHtmlTemplatePaths()
45
	{
46
		return self::getAimeos()->getTemplatePaths( 'client/html/templates' );
47
	}
48
49
50
	/**
51
	 * @param string $site
52
	 */
53
	private static function createContext( $site )
54
	{
55
		$ctx = new \Aimeos\MShop\Context\Item\Standard();
56
		$aimeos = self::getAimeos();
57
58
59
		$paths = $aimeos->getConfigPaths();
60
		$paths[] = __DIR__ . DIRECTORY_SEPARATOR . 'config';
61
62
		$conf = new \Aimeos\MW\Config\PHPArray( array(), $paths );
63
		$ctx->setConfig( $conf );
64
65
66
		$dbm = new \Aimeos\MW\DB\Manager\DBAL( $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
		$cache = new \Aimeos\MW\Cache\None();
75
		$ctx->setCache( $cache );
76
77
78
		$i18n = new \Aimeos\MW\Translation\None( 'de' );
79
		$ctx->setI18n( array( 'de' => $i18n ) );
80
81
82
		$session = new \Aimeos\MW\Session\None();
83
		$ctx->setSession( $session );
84
85
86
		$localeManager = \Aimeos\MShop\Locale\Manager\Factory::create( $ctx );
87
		$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\Service\Manager\Lists\Type\Iface or Aimeos\MShop\Price\Manager\Iface or Aimeos\MShop\Attribute\Manager\Type\Iface or Aimeos\MShop\Review\Manager\Iface or Aimeos\MShop\Price\Manager\Lists\Type\Iface or Aimeos\MShop\Media\Manager\Type\Iface or Aimeos\MShop\Coupon\Manager\Code\Iface or Aimeos\MShop\Order\Manager\Base\Coupon\Iface or Aimeos\MShop\Product\Manager\Iface or Aimeos\MShop\Supplier\Manager\Iface or Aimeos\MShop\Price\Manager\Property\Type\Iface or Aimeos\MShop\Common\Manager\Property\Iface or Aimeos\MShop\Customer\Manager\Property\Iface or Aimeos\MShop\Order\Manager\Base\Service\Iface or Aimeos\MShop\Order\Manager\Base\Iface or Aimeos\MShop\Price\Manager\Lists\Iface or Aimeos\MShop\Cms\Manager\Lists\Type\Iface or Aimeos\MShop\Supplier\Manager\Lists\Type\Iface or Aimeos\MShop\Order\Manag...Service\Attribute\Iface or Aimeos\MShop\Service\Manager\Lists\Iface or Aimeos\MShop\Tag\Manager\Type\Iface or Aimeos\MShop\Text\Manager\Lists\Iface or Aimeos\MShop\Price\Manager\Type\Iface or Aimeos\MShop\Locale\Manager\Currency\Iface or Aimeos\MShop\Order\Manag...Product\Attribute\Iface or Aimeos\MShop\Media\Manager\Lists\Type\Iface or Aimeos\MShop\Catalog\Manager\Lists\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\Attribute\Manager\Property\Type\Iface or Aimeos\MShop\Service\Manager\Type\Iface or Aimeos\MShop\Product\Manager\Lists\Iface or Aimeos\MShop\Customer\Manager\Property\Type\Iface or Aimeos\MShop\Order\Manager\Iface or Aimeos\MShop\Customer\Manager\Iface or Aimeos\MShop\Media\Manager\Iface or Aimeos\MShop\Rule\Manager\Type\Iface or Aimeos\MShop\Customer\Manager\Lists\Type\Iface or Aimeos\MShop\Attribute\Manager\Lists\Iface or Aimeos\MShop\Product\Manager\Property\Type\Iface or Aimeos\MShop\Media\Manager\Lists\Iface or Aimeos\MShop\Plugin\Manager\Iface or Aimeos\MShop\Order\Manager\Base\Address\Iface or Aimeos\MShop\Catalog\Manager\Iface or Aimeos\MShop\Locale\Manager\Site\Iface or Aimeos\MShop\Product\Manager\Type\Iface or Aimeos\MShop\Supplier\Manager\Lists\Iface or Aimeos\MShop\Stock\Manager\Type\Iface or Aimeos\MShop\Text\Manager\Iface or Aimeos\MShop\Common\Manager\Type\Iface or Aimeos\MAdmin\Job\Manager\Iface or Aimeos\MShop\Customer\Manager\Group\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\Cms\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\Plugin\Manager\Type\Iface or Aimeos\MShop\Stock\Manager\Iface or Aimeos\MShop\Attribute\Manager\Property\Iface or Aimeos\MShop\Subscription\Manager\Iface or Aimeos\MShop\Media\Manager\Property\Type\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\MShop\Attribute\Manager\Lists\Type\Iface or Aimeos\MAdmin\Log\Manager\Iface or Aimeos\MShop\Cms\Manager\Lists\Iface or Aimeos\MAdmin\Cache\Manager\Iface or Aimeos\MShop\Order\Manager\Base\Product\Iface or Aimeos\MShop\Price\Manager\Property\Iface or Aimeos\MShop\Customer\Manager\Lists\Iface or Aimeos\MShop\Catalog\Manager\Lists\Type\Iface or Aimeos\MShop\Index\Manager\Iface or Aimeos\MShop\Index\Manager\Attribute\Iface or Aimeos\MShop\Index\Manager\Text\Iface or Aimeos\MShop\Index\Manager\Supplier\Iface or Aimeos\MShop\Index\Manager\Catalog\Iface or Aimeos\MShop\Index\Manager\Price\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

87
		/** @scrutinizer ignore-call */ 
88
  $localeItem = $localeManager->bootstrap( $site, '', '', false );
Loading history...
88
89
		$ctx->setLocale( $localeItem );
90
91
		$ctx->setEditor( 'ai-cms-grapesjs:lib/custom' );
92
93
		return $ctx;
94
	}
95
96
97
	public static function view( $site = 'unittest', \Aimeos\MW\Config\Iface $config = null )
98
	{
99
		if( $config === null ) {
100
			$config = self::getContext( $site )->getConfig();
101
		}
102
103
		$view = new \Aimeos\MW\View\Standard( self::getHtmlTemplatePaths() );
104
105
		$trans = new \Aimeos\MW\Translation\None( 'de_DE' );
106
		$helper = new \Aimeos\MW\View\Helper\Translate\Standard( $view, $trans );
107
		$view->addHelper( 'translate', $helper );
108
109
		$helper = new \Aimeos\MW\View\Helper\Url\Standard( $view, 'http://baseurl' );
110
		$view->addHelper( 'url', $helper );
111
112
		$helper = new \Aimeos\MW\View\Helper\Number\Standard( $view, '.', '' );
113
		$view->addHelper( 'number', $helper );
114
115
		$helper = new \Aimeos\MW\View\Helper\Date\Standard( $view, 'Y-m-d' );
116
		$view->addHelper( 'date', $helper );
117
118
		$config = new \Aimeos\MW\Config\Decorator\Protect( $config, ['client', 'resource/fs/baseurl'] );
119
		$helper = new \Aimeos\MW\View\Helper\Config\Standard( $view, $config );
120
		$view->addHelper( 'config', $helper );
121
122
		$helper = new \Aimeos\MW\View\Helper\Csrf\Standard( $view, '_csrf_token', '_csrf_value' );
123
		$view->addHelper( 'csrf', $helper );
124
125
		$psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory();
126
		$helper = new \Aimeos\MW\View\Helper\Request\Standard( $view, $psr17Factory->createServerRequest( 'GET', 'https://aimeos.org' ) );
127
		$view->addHelper( 'request', $helper );
128
129
		$helper = new \Aimeos\MW\View\Helper\Response\Standard( $view, $psr17Factory->createResponse() );
130
		$view->addHelper( 'response', $helper );
131
132
		return $view;
133
	}
134
}
135