Completed
Branch master (d2e225)
by Aimeos
03:06
created

TestHelperJadm::createContext()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 44
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 24
nc 1
nop 1
dl 0
loc 44
rs 9.536
c 1
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2015-2018
6
 */
7
8
9
class TestHelperJadm
10
{
11
	private static $aimeos;
12
	private static $context;
13
14
15
	public static function bootstrap()
16
	{
17
		self::getAimeos();
18
	}
19
20
21
	public static function getContext( $site = 'unittest' )
22
	{
23
		if( !isset( self::$context[$site] ) ) {
24
			self::$context[$site] = self::createContext( $site );
25
		}
26
27
		return clone self::$context[$site];
28
	}
29
30
31
	public static function getAimeos()
32
	{
33
		if( !isset( self::$aimeos ) )
34
		{
35
			require_once 'Bootstrap.php';
36
			spl_autoload_register( 'Aimeos\\Bootstrap::autoload' );
37
38
			$extdir = dirname( dirname( dirname( dirname( __FILE__ ) ) ) );
39
			self::$aimeos = new \Aimeos\Bootstrap( array( $extdir ), false );
40
		}
41
42
		return self::$aimeos;
43
	}
44
45
46
	public static function getJsonadmPaths()
47
	{
48
		return self::getAimeos()->getCustomPaths( 'admin/jsonadm/templates' );
49
	}
50
51
52
	private static function createContext( $site )
53
	{
54
		$ctx = new \Aimeos\MShop\Context\Item\Standard();
55
		$aimeos = self::getAimeos();
56
57
58
		$paths = $aimeos->getConfigPaths( 'mysql' );
59
		$paths[] = __DIR__ . DIRECTORY_SEPARATOR . 'config';
60
		$file = __DIR__ . DIRECTORY_SEPARATOR . 'confdoc.ser';
61
62
		$conf = new \Aimeos\MW\Config\PHPArray( [], $paths );
63
		$conf = new \Aimeos\MW\Config\Decorator\Memory( $conf );
64
		$conf = new \Aimeos\MW\Config\Decorator\Documentor( $conf, $file );
65
		$ctx->setConfig( $conf );
66
67
68
		$dbm = new \Aimeos\MW\DB\Manager\PDO( $conf );
69
		$ctx->setDatabaseManager( $dbm );
70
71
72
		$logger = new \Aimeos\MW\Logger\File( $site . '.log', \Aimeos\MW\Logger\Base::DEBUG );
73
		$ctx->setLogger( $logger );
74
75
76
		$session = new \Aimeos\MW\Session\None();
77
		$ctx->setSession( $session );
78
79
80
		$i18n = new \Aimeos\MW\Translation\None( 'de' );
81
		$ctx->setI18n( array( 'de' => $i18n ) );
82
83
84
		$localeManager = \Aimeos\MShop::create( $ctx, 'locale' );
85
		$locale = $localeManager->bootstrap( $site, 'de', '', false );
1 ignored issue
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 Aimeos\MShop\Common\Manager\Iface such as Aimeos\MShop\Locale\Manager\Iface or Aimeos\MShop\Common\Manager\Decorator\Base or Aimeos\MShop\Service\Manager\Lists\Type\Standard or Aimeos\MShop\Price\Manager\Standard or Aimeos\MShop\Attribute\Manager\Type\Standard or Aimeos\MShop\Price\Manager\Lists\Type\Standard or Aimeos\MShop\Media\Manager\Type\Standard or Aimeos\MShop\Coupon\Manager\Code\Standard or Aimeos\MShop\Order\Manager\Base\Coupon\Standard or Aimeos\MShop\Product\Manager\Standard or Aimeos\MShop\Index\Manager\Standard or Aimeos\MShop\Index\Manager\Attribute\Standard or Aimeos\MShop\Index\Manager\Text\Standard or Aimeos\MShop\Index\Manager\Supplier\Standard or Aimeos\MShop\Index\Manager\Catalog\Standard or Aimeos\MShop\Index\Manager\Price\Standard or Aimeos\MShop\Supplier\Manager\Standard or Aimeos\MShop\Customer\Manager\Property\Standard or Aimeos\MShop\Order\Manager\Base\Service\Standard or Aimeos\MShop\Order\Manager\Base\Standard or Aimeos\MShop\Price\Manager\Lists\Standard or Aimeos\MShop\Supplier\Manager\Lists\Type\Standard or Aimeos\MShop\Order\Manag...vice\Attribute\Standard or Aimeos\MShop\Service\Manager\Lists\Standard or Aimeos\MShop\Tag\Manager\Type\Standard or Aimeos\MShop\Text\Manager\Lists\Standard or Aimeos\MShop\Price\Manager\Type\Standard or Aimeos\MShop\Locale\Manager\Currency\Standard or Aimeos\MShop\Order\Manag...duct\Attribute\Standard or Aimeos\MShop\Media\Manager\Lists\Type\Standard or Aimeos\MShop\Catalog\Manager\Lists\Standard or Aimeos\MShop\Tag\Manager\Standard or Aimeos\MShop\Coupon\Manager\Standard or Aimeos\MShop\Attribute\Manager\Standard or Aimeos\MShop\Attribute\M...\Property\Type\Standard or Aimeos\MShop\Service\Manager\Type\Standard or Aimeos\MShop\Product\Manager\Lists\Standard or Aimeos\MShop\Customer\Ma...\Property\Type\Standard or Aimeos\MShop\Order\Manager\Standard or Aimeos\MShop\Customer\Manager\Standard or Aimeos\MShop\Media\Manager\Standard or Aimeos\MShop\Customer\Manager\Lists\Type\Standard or Aimeos\MShop\Attribute\Manager\Lists\Standard or Aimeos\MShop\Product\Man...\Property\Type\Standard or Aimeos\MShop\Media\Manager\Lists\Standard or Aimeos\MShop\Plugin\Manager\Standard or Aimeos\MShop\Order\Manager\Base\Address\Standard or Aimeos\MShop\Catalog\Manager\Standard or Aimeos\MShop\Locale\Manager\Site\Standard or Aimeos\MShop\Product\Manager\Type\Standard or Aimeos\MShop\Supplier\Manager\Lists\Standard or Aimeos\MShop\Stock\Manager\Type\Standard or Aimeos\MShop\Text\Manager\Standard or Aimeos\MAdmin\Job\Manager\Standard or Aimeos\MShop\Customer\Manager\Group\Standard or Aimeos\MShop\Product\Manager\Lists\Type\Standard or Aimeos\MShop\Text\Manager\Lists\Type\Standard or Aimeos\MShop\Text\Manager\Type\Standard or Aimeos\MShop\Order\Manager\Status\Standard or Aimeos\MShop\Supplier\Manager\Address\Standard or Aimeos\MShop\Customer\Manager\Address\Standard or Aimeos\MShop\Plugin\Manager\Type\Standard or Aimeos\MShop\Stock\Manager\Standard or Aimeos\MShop\Stock\Manager\Nolimit or Aimeos\MShop\Attribute\Manager\Property\Standard or Aimeos\MShop\Subscription\Manager\Standard or Aimeos\MShop\Media\Manager\Property\Type\Standard or Aimeos\MShop\Product\Manager\Property\Standard or Aimeos\MShop\Locale\Manager\Language\Standard or Aimeos\MShop\Media\Manager\Property\Standard or Aimeos\MShop\Service\Manager\Standard or Aimeos\MShop\Attribute\Manager\Lists\Type\Standard or Aimeos\MAdmin\Log\Manager\Standard or Aimeos\MAdmin\Cache\Manager\Standard or Aimeos\MAdmin\Cache\Manager\None or Aimeos\MShop\Order\Manager\Base\Product\Standard or Aimeos\MShop\Customer\Manager\Lists\Standard or Aimeos\MShop\Catalog\Manager\Lists\Type\Standard. ( Ignorable by Annotation )

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

85
		/** @scrutinizer ignore-call */ 
86
  $locale = $localeManager->bootstrap( $site, 'de', '', false );
Loading history...
86
		$ctx->setLocale( $locale );
87
88
89
		$view = self::createView( $conf );
90
		$ctx->setView( $view );
91
92
93
		$ctx->setEditor( 'core:admin/jsonadm' );
94
95
		return $ctx;
96
	}
97
98
99
	protected static function createView( \Aimeos\MW\Config\Iface $config )
100
	{
101
		$tmplpaths = self::getAimeos()->getCustomPaths( 'admin/jsonadm/templates' );
102
103
		$view = new \Aimeos\MW\View\Standard( $tmplpaths );
104
105
		$helper = new \Aimeos\MW\View\Helper\Access\All( $view );
106
		$view->addHelper( 'access', $helper );
107
108
		$trans = new \Aimeos\MW\Translation\None( 'de_DE' );
109
		$helper = new \Aimeos\MW\View\Helper\Translate\Standard( $view, $trans );
110
		$view->addHelper( 'translate', $helper );
111
112
		$helper = new \Aimeos\MW\View\Helper\Url\Standard( $view, 'http://baseurl' );
113
		$view->addHelper( 'url', $helper );
114
115
		$helper = new \Aimeos\MW\View\Helper\Number\Standard( $view, '.', '' );
116
		$view->addHelper( 'number', $helper );
117
118
		$helper = new \Aimeos\MW\View\Helper\Date\Standard( $view, 'Y-m-d' );
119
		$view->addHelper( 'date', $helper );
120
121
		$config = new \Aimeos\MW\Config\Decorator\Protect( $config, array( 'admin/jsonadm' ) );
122
		$helper = new \Aimeos\MW\View\Helper\Config\Standard( $view, $config );
123
		$view->addHelper( 'config', $helper );
124
125
		$helper = new \Aimeos\MW\View\Helper\Request\Standard( $view, new \Zend\Diactoros\ServerRequest() );
126
		$view->addHelper( 'request', $helper );
127
128
		$helper = new \Aimeos\MW\View\Helper\Response\Standard( $view, new \Zend\Diactoros\Response() );
129
		$view->addHelper( 'response', $helper );
130
131
		return $view;
132
	}
133
}
134