Completed
Push — master ( 96b5a6...c41e60 )
by Aimeos
03:06
created

TestHelperJobs::errorHandler()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 4
1
<?php
2
3
4
/**
5
 * @copyright Metaways Infosystems GmbH, 2011
6
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
7
 * @copyright Aimeos (aimeos.org), 2015
8
 */
9
class TestHelperJobs
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
10
{
11
	private static $aimeos;
12
	private static $context;
13
14
15
	public static function bootstrap()
16
	{
17
		self::getAimeos();
18
		\Aimeos\MShop\Factory::setCache( false );
19
	}
20
21
22 View Code Duplication
	public static function getContext( $site = 'unittest' )
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
23
	{
24
		if( !isset( self::$context[$site] ) ) {
25
			self::$context[$site] = self::createContext( $site );
26
		}
27
28
		return clone self::$context[$site];
29
	}
30
31
32 View Code Duplication
	public static function getAimeos()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
33
	{
34
		if( !isset( self::$aimeos ) )
35
		{
36
			require_once 'Bootstrap.php';
37
			spl_autoload_register( 'Aimeos\\Bootstrap::autoload' );
38
39
			$extdir = dirname( dirname( dirname( dirname( dirname( __FILE__ ) ) ) ) );
40
			self::$aimeos = new \Aimeos\Bootstrap( array( $extdir ), true );
41
		}
42
43
		return self::$aimeos;
44
	}
45
46
47
	public static function getControllerPaths()
48
	{
49
		return self::getAimeos()->getCustomPaths( 'controller/jobs' );
50
	}
51
52
53
	/**
54
	 * @param string $site
55
	 */
56
	private static function createContext( $site )
57
	{
58
		$ctx = new \Aimeos\MShop\Context\Item\Standard();
59
		$aimeos = self::getAimeos();
60
61
62
		$paths = $aimeos->getConfigPaths( 'mysql' );
63
		$paths[] = __DIR__ . DIRECTORY_SEPARATOR . 'config';
64
		$file = __DIR__ . DIRECTORY_SEPARATOR . 'confdoc.ser';
65
66
		$conf = new \Aimeos\MW\Config\PHPArray( array(), $paths );
67
		$conf = new \Aimeos\MW\Config\Decorator\Memory( $conf );
68
		$conf = new \Aimeos\MW\Config\Decorator\Documentor( $conf, $file );
69
		$ctx->setConfig( $conf );
70
71
72
		$logger = new \Aimeos\MW\Logger\File( $site . '.log', \Aimeos\MW\Logger\Base::DEBUG );
73
		$ctx->setLogger( $logger );
74
75
76
		$dbm = new \Aimeos\MW\DB\Manager\PDO( $conf );
77
		$ctx->setDatabaseManager( $dbm );
78
79
80
		$fs = new \Aimeos\MW\Filesystem\Manager\Standard( $conf );
81
		$ctx->setFilesystemManager( $fs );
82
83
84
		$mq = new \Aimeos\MW\MQueue\Manager\Standard( $conf );
85
		$ctx->setMessageQueueManager( $mq );
86
87
88
		$session = new \Aimeos\MW\Session\None();
89
		$ctx->setSession( $session );
90
91
92
		$i18n = new \Aimeos\MW\Translation\None( 'de' );
93
		$ctx->setI18n( array( 'de' => $i18n ) );
94
95
96
		$localeManager = \Aimeos\MShop\Locale\Manager\Factory::createManager( $ctx );
97
		$locale = $localeManager->bootstrap( $site, 'de', '', false );
98
		$ctx->setLocale( $locale );
99
100
101
		$view = self::createView( $conf );
102
		$ctx->setView( $view );
103
104
105
		$ctx->setEditor( 'core:controller/jobs' );
106
107
		return $ctx;
108
	}
109
110
111
	protected static function createView( \Aimeos\MW\Config\Iface $config )
112
	{
113
		$tmplpaths = array_merge_recursive(
114
			self::getAimeos()->getCustomPaths( 'client/html/templates' ),
115
			self::getAimeos()->getCustomPaths( 'controller/jobs/templates' )
116
		);
117
118
		$view = new \Aimeos\MW\View\Standard( $tmplpaths );
119
120
		$trans = new \Aimeos\MW\Translation\None( 'de_DE' );
121
		$helper = new \Aimeos\MW\View\Helper\Translate\Standard( $view, $trans );
122
		$view->addHelper( 'translate', $helper );
123
124
		$helper = new \Aimeos\MW\View\Helper\Url\Standard( $view, 'http://baseurl' );
125
		$view->addHelper( 'url', $helper );
126
127
		$helper = new \Aimeos\MW\View\Helper\Number\Standard( $view, '.', '' );
128
		$view->addHelper( 'number', $helper );
129
130
		$helper = new \Aimeos\MW\View\Helper\Date\Standard( $view, 'Y-m-d' );
131
		$view->addHelper( 'date', $helper );
132
133
		$config = new \Aimeos\MW\Config\Decorator\Protect( $config, array( 'controller/jobs', 'client/html' ) );
134
		$helper = new \Aimeos\MW\View\Helper\Config\Standard( $view, $config );
135
		$view->addHelper( 'config', $helper );
136
137
		return $view;
138
	}
139
}
140