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

TestHelperHtml::getView()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
nc 1
nop 0
dl 0
loc 21
c 1
b 0
f 0
cc 1
rs 9.8333
1
<?php
2
3
4
class TestHelperHtml
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 view()
45
	{
46
		$view = new \Aimeos\MW\View\Standard( self::getHtmlTemplatePaths() );
47
48
		$trans = new \Aimeos\MW\Translation\None( 'en' );
49
		$helper = new \Aimeos\MW\View\Helper\Translate\Standard( $view, $trans );
50
		$view->addHelper( 'translate', $helper );
51
52
		$helper = new \Aimeos\MW\View\Helper\Url\Standard( $view, 'baseurl' );
53
		$view->addHelper( 'url', $helper );
54
55
		$helper = new \Aimeos\MW\View\Helper\Number\Standard( $view, '.', '' );
56
		$view->addHelper( 'number', $helper );
57
58
		$helper = new \Aimeos\MW\View\Helper\Date\Standard( $view, 'Y-m-d' );
59
		$view->addHelper( 'date', $helper );
60
61
		$helper = new \Aimeos\MW\View\Helper\Config\Standard( $view, self::getContext()->getConfig() );
62
		$view->addHelper( 'config', $helper );
63
64
		return $view;
65
	}
66
67
68
	public static function getHtmlTemplatePaths()
69
	{
70
		return self::getAimeos()->getTemplatePaths( 'client/html/templates' );
71
	}
72
73
74
	private static function createContext( $site )
75
	{
76
		$ctx = new \Aimeos\MShop\Context\Item\Standard();
77
		$aimeos = self::getAimeos();
78
79
80
		$paths = $aimeos->getConfigPaths();
81
		$paths[] = __DIR__ . DIRECTORY_SEPARATOR . 'config';
82
83
		$conf = new \Aimeos\MW\Config\PHPArray( array(), $paths );
84
		$ctx->setConfig( $conf );
85
86
87
		$dbm = new \Aimeos\MW\DB\Manager\DBAL( $conf );
88
		$ctx->setDatabaseManager( $dbm );
89
90
91
		$logger = new \Aimeos\MW\Logger\File( $site . '.log', \Aimeos\MW\Logger\Base::DEBUG );
92
		$ctx->setLogger( $logger );
93
94
95
		$cache = new \Aimeos\MW\Cache\None();
96
		$ctx->setCache( $cache );
97
98
99
		$i18n = new \Aimeos\MW\Translation\None( 'en' );
100
		$ctx->setI18n( array( 'en' => $i18n ) );
101
102
103
		$session = new \Aimeos\MW\Session\None();
104
		$ctx->setSession( $session );
105
106
107
		$mail = new \Aimeos\MW\Mail\None();
108
		$ctx->setMail( $mail );
109
110
111
		$localeManager = \Aimeos\MShop\Locale\Manager\Factory::create( $ctx );
112
		$locale = $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

112
		/** @scrutinizer ignore-call */ 
113
  $locale = $localeManager->bootstrap( $site, '', '', false );
Loading history...
113
		$ctx->setLocale( $locale );
114
115
116
		$ctx->setEditor( 'ai-cms-grapesjs:client/html' );
117
118
		return $ctx;
119
	}
120
}