TestHelperJsonadm::bootstrap()   A
last analyzed

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
/**
5
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
6
 * @copyright Aimeos (aimeos.org), 2015-2016
7
 */
8
class TestHelperJsonadm
9
{
10
	private static $aimeos;
11
	private static $context;
12
13
14
	public static function bootstrap()
15
	{
16
		$aimeos = self::getAimeos();
17
18
		$includepaths = $aimeos->getIncludePaths();
19
		$includepaths[] = get_include_path();
20
		set_include_path( implode( PATH_SEPARATOR, $includepaths ) );
21
	}
22
23
24
	private static function getAimeos()
25
	{
26
		if( !isset( self::$aimeos ) )
27
		{
28
			require_once 'Bootstrap.php';
29
			spl_autoload_register( 'Aimeos\\Bootstrap::autoload' );
30
31
			self::$aimeos = new \Aimeos\Bootstrap();
32
		}
33
34
		return self::$aimeos;
35
	}
36
37
38
	public static function getContext( $site = 'unittest' )
39
	{
40
		if( !isset( self::$context[$site] ) ) {
41
			self::$context[$site] = self::createContext( $site );
42
		}
43
44
		return clone self::$context[$site];
45
	}
46
47
48
	public static function getControllerPaths()
49
	{
50
		return self::getAimeos()->getCustomPaths( 'admin/jsonadm' );
51
	}
52
53
54
	public static function getTemplatePaths()
55
	{
56
		return self::getAimeos()->getTemplatePaths( 'admin/jsonadm/templates' );
57
	}
58
59
60
	private static function createContext( $site )
61
	{
62
		$ctx = new \Aimeos\MShop\Context\Item\Standard();
63
		$aimeos = self::getAimeos();
64
65
66
		$paths = $aimeos->getConfigPaths();
67
		$paths[] = __DIR__ . DIRECTORY_SEPARATOR . 'config';
68
69
		$conf = new \Aimeos\MW\Config\PHPArray( array(), $paths );
70
		$conf = new \Aimeos\MW\Config\Decorator\Memory( $conf );
71
		$ctx->setConfig( $conf );
72
73
74
		$dbm = new \Aimeos\MW\DB\Manager\DBAL( $conf );
75
		$ctx->setDatabaseManager( $dbm );
76
77
78
		$logger = new \Aimeos\MW\Logger\File( $site . '.log', \Aimeos\MW\Logger\Base::DEBUG );
79
		$ctx->setLogger( $logger );
80
81
82
		$cache = new \Aimeos\MW\Cache\None();
83
		$ctx->setCache( $cache );
84
85
86
		$i18n = new \Aimeos\MW\Translation\None( 'de' );
87
		$ctx->setI18n( array( 'de' => $i18n ) );
88
89
90
		$session = new \Aimeos\MW\Session\None();
91
		$ctx->setSession( $session );
92
93
94
		$localeManager = \Aimeos\MShop\Locale\Manager\Factory::create( $ctx );
95
		$locale = $localeManager->bootstrap( $site, 'de', '', 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

95
		/** @scrutinizer ignore-call */ 
96
  $locale = $localeManager->bootstrap( $site, 'de', '', false );
Loading history...
96
		$ctx->setLocale( $locale );
97
98
99
		$view = self::createView( $conf );
100
		$ctx->setView( $view );
101
102
103
		$ctx->setEditor( 'ai-cms-grapesjs:admin/jsonadm' );
104
105
		return $ctx;
106
	}
107
108
109
	protected static function createView( \Aimeos\MW\Config\Iface $config )
110
	{
111
		$tmplpaths = self::getAimeos()->getTemplatePaths( 'admin/jsonadm/templates' );
112
113
		$view = new \Aimeos\MW\View\Standard( $tmplpaths );
114
115
		$helper = new \Aimeos\MW\View\Helper\Access\All( $view );
116
		$view->addHelper( 'access', $helper );
117
118
		$trans = new \Aimeos\MW\Translation\None( 'de_DE' );
119
		$helper = new \Aimeos\MW\View\Helper\Translate\Standard( $view, $trans );
120
		$view->addHelper( 'translate', $helper );
121
122
		$helper = new \Aimeos\MW\View\Helper\Url\Standard( $view, 'http://baseurl' );
123
		$view->addHelper( 'url', $helper );
124
125
		$helper = new \Aimeos\MW\View\Helper\Number\Standard( $view, '.', '' );
126
		$view->addHelper( 'number', $helper );
127
128
		$helper = new \Aimeos\MW\View\Helper\Date\Standard( $view, 'Y-m-d' );
129
		$view->addHelper( 'date', $helper );
130
131
		$config = new \Aimeos\MW\Config\Decorator\Protect( $config, array( 'admin/jsonadm' ) );
132
		$helper = new \Aimeos\MW\View\Helper\Config\Standard( $view, $config );
133
		$view->addHelper( 'config', $helper );
134
135
		$psr17Factory = new \Nyholm\Psr7\Factory\Psr17Factory();
136
		$helper = new \Aimeos\MW\View\Helper\Request\Standard( $view, $psr17Factory->createServerRequest( 'GET', 'https://aimeos.org' ) );
137
		$view->addHelper( 'request', $helper );
138
139
		$helper = new \Aimeos\MW\View\Helper\Response\Standard( $view, $psr17Factory->createResponse() );
140
		$view->addHelper( 'response', $helper );
141
142
		return $view;
143
	}
144
}
145