Completed
Push — master ( ac109f...19c432 )
by Aimeos
05:47
created
client/jsonapi/tests/Client/JsonApi/Locale/StandardTest.php 1 patch
Spacing   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -22,20 +22,20 @@  discard block
 block discarded – undo
22 22
 		$templatePaths = \TestHelperJapi::getTemplatePaths();
23 23
 		$this->view = $this->context->getView();
24 24
 
25
-		$this->object = new \Aimeos\Client\JsonApi\Locale\Standard( $this->context, $this->view, $templatePaths, 'locale' );
25
+		$this->object = new \Aimeos\Client\JsonApi\Locale\Standard($this->context, $this->view, $templatePaths, 'locale');
26 26
 	}
27 27
 
28 28
 
29 29
 	public function testGetItem()
30 30
 	{
31
-		$localeManager = \Aimeos\MShop\Factory::createManager( $this->context, 'locale' );
31
+		$localeManager = \Aimeos\MShop\Factory::createManager($this->context, 'locale');
32 32
 		$search = $localeManager->createSearch();
33
-		$search->setSortations( [$search->sort( '+', 'locale.position' )] );
34
-		$search->setSlice( 0, 1 );
35
-		$localeItems = $localeManager->searchItems( $search );
33
+		$search->setSortations([$search->sort('+', 'locale.position')]);
34
+		$search->setSlice(0, 1);
35
+		$localeItems = $localeManager->searchItems($search);
36 36
 
37
-		if( ( $localeItem = reset( $localeItems ) ) === false ) {
38
-			throw new \Exception( 'No locale item found' );
37
+		if (($localeItem = reset($localeItems)) === false) {
38
+			throw new \Exception('No locale item found');
39 39
 		}
40 40
 
41 41
 
@@ -46,24 +46,24 @@  discard block
 block discarded – undo
46 46
 			)
47 47
 		);
48 48
 
49
-		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params );
50
-		$this->view->addHelper( 'param', $helper );
49
+		$helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params);
50
+		$this->view->addHelper('param', $helper);
51 51
 
52
-		$response = $this->object->get( $this->view->request(), $this->view->response() );
53
-		$result = json_decode( (string) $response->getBody(), true );
52
+		$response = $this->object->get($this->view->request(), $this->view->response());
53
+		$result = json_decode((string) $response->getBody(), true);
54 54
 
55 55
 
56
-		$this->assertEquals( 200, $response->getStatusCode() );
57
-		$this->assertEquals( 1, count( $response->getHeader( 'Allow' ) ) );
58
-		$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) );
56
+		$this->assertEquals(200, $response->getStatusCode());
57
+		$this->assertEquals(1, count($response->getHeader('Allow')));
58
+		$this->assertEquals(1, count($response->getHeader('Content-Type')));
59 59
 
60
-		$this->assertEquals( 1, $result['meta']['total'] );
61
-		$this->assertEquals( 'locale', $result['data']['type'] );
62
-		$this->assertGreaterThan( 0, $result['data']['attributes']['locale.id'] );
63
-		$this->assertEquals( 'de', $result['data']['attributes']['locale.languageid'] );
64
-		$this->assertEquals( 'EUR', $result['data']['attributes']['locale.currencyid'] );
60
+		$this->assertEquals(1, $result['meta']['total']);
61
+		$this->assertEquals('locale', $result['data']['type']);
62
+		$this->assertGreaterThan(0, $result['data']['attributes']['locale.id']);
63
+		$this->assertEquals('de', $result['data']['attributes']['locale.languageid']);
64
+		$this->assertEquals('EUR', $result['data']['attributes']['locale.currencyid']);
65 65
 
66
-		$this->assertArrayNotHasKey( 'errors', $result );
66
+		$this->assertArrayNotHasKey('errors', $result);
67 67
 	}
68 68
 
69 69
 
@@ -75,25 +75,25 @@  discard block
 block discarded – undo
75 75
 			),
76 76
 			'sort' => 'locale.position',
77 77
 		);
78
-		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params );
79
-		$this->view->addHelper( 'param', $helper );
78
+		$helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params);
79
+		$this->view->addHelper('param', $helper);
80 80
 
81
-		$response = $this->object->get( $this->view->request(), $this->view->response() );
82
-		$result = json_decode( (string) $response->getBody(), true );
81
+		$response = $this->object->get($this->view->request(), $this->view->response());
82
+		$result = json_decode((string) $response->getBody(), true);
83 83
 
84 84
 
85
-		$this->assertEquals( 200, $response->getStatusCode() );
86
-		$this->assertEquals( 1, count( $response->getHeader( 'Allow' ) ) );
87
-		$this->assertEquals( 1, count( $response->getHeader( 'Content-Type' ) ) );
85
+		$this->assertEquals(200, $response->getStatusCode());
86
+		$this->assertEquals(1, count($response->getHeader('Allow')));
87
+		$this->assertEquals(1, count($response->getHeader('Content-Type')));
88 88
 
89
-		$this->assertEquals( 1, $result['meta']['total'] );
90
-		$this->assertEquals( 1, count( $result['data'] ) );
91
-		$this->assertEquals( 'locale', $result['data'][0]['type'] );
92
-		$this->assertEquals( 3, count( $result['data'][0]['attributes'] ) );
93
-		$this->assertEquals( 'en', $result['data'][0]['attributes']['locale.languageid'] );
94
-		$this->assertEquals( 'EUR', $result['data'][0]['attributes']['locale.currencyid'] );
89
+		$this->assertEquals(1, $result['meta']['total']);
90
+		$this->assertEquals(1, count($result['data']));
91
+		$this->assertEquals('locale', $result['data'][0]['type']);
92
+		$this->assertEquals(3, count($result['data'][0]['attributes']));
93
+		$this->assertEquals('en', $result['data'][0]['attributes']['locale.languageid']);
94
+		$this->assertEquals('EUR', $result['data'][0]['attributes']['locale.currencyid']);
95 95
 
96
-		$this->assertArrayNotHasKey( 'errors', $result );
96
+		$this->assertArrayNotHasKey('errors', $result);
97 97
 	}
98 98
 
99 99
 
@@ -101,20 +101,20 @@  discard block
 block discarded – undo
101 101
 	{
102 102
 		$params = array(
103 103
 			'filter' => array(
104
-				'>=' => array( 'locale.position' => 0 ),
104
+				'>=' => array('locale.position' => 0),
105 105
 			),
106 106
 			'sort' => '-locale.position',
107 107
 		);
108
-		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $params );
109
-		$this->view->addHelper( 'param', $helper );
108
+		$helper = new \Aimeos\MW\View\Helper\Param\Standard($this->view, $params);
109
+		$this->view->addHelper('param', $helper);
110 110
 
111
-		$response = $this->object->get( $this->view->request(), $this->view->response() );
112
-		$result = json_decode( (string) $response->getBody(), true );
111
+		$response = $this->object->get($this->view->request(), $this->view->response());
112
+		$result = json_decode((string) $response->getBody(), true);
113 113
 
114 114
 
115
-		$this->assertEquals( 200, $response->getStatusCode() );
116
-		$this->assertEquals( 1, $result['meta']['total'] );
117
-		$this->assertArrayNotHasKey( 'errors', $result );
115
+		$this->assertEquals(200, $response->getStatusCode());
116
+		$this->assertEquals(1, $result['meta']['total']);
117
+		$this->assertArrayNotHasKey('errors', $result);
118 118
 	}
119 119
 
120 120
 
@@ -122,21 +122,21 @@  discard block
 block discarded – undo
122 122
 	{
123 123
 		$templatePaths = \TestHelperJapi::getTemplatePaths();
124 124
 
125
-		$object = $this->getMockBuilder( '\Aimeos\Client\JsonApi\Locale\Standard' )
126
-			->setConstructorArgs( [$this->context, $this->view, $templatePaths, 'locale'] )
127
-			->setMethods( ['getItems'] )
125
+		$object = $this->getMockBuilder('\Aimeos\Client\JsonApi\Locale\Standard')
126
+			->setConstructorArgs([$this->context, $this->view, $templatePaths, 'locale'])
127
+			->setMethods(['getItems'])
128 128
 			->getMock();
129 129
 
130
-		$object->expects( $this->once() )->method( 'getItems' )
131
-			->will( $this->throwException( new \Aimeos\MShop\Exception() ) );
130
+		$object->expects($this->once())->method('getItems')
131
+			->will($this->throwException(new \Aimeos\MShop\Exception()));
132 132
 
133 133
 
134
-		$response = $object->get( $this->view->request(), $this->view->response() );
135
-		$result = json_decode( (string) $response->getBody(), true );
134
+		$response = $object->get($this->view->request(), $this->view->response());
135
+		$result = json_decode((string) $response->getBody(), true);
136 136
 
137 137
 
138
-		$this->assertEquals( 404, $response->getStatusCode() );
139
-		$this->assertArrayHasKey( 'errors', $result );
138
+		$this->assertEquals(404, $response->getStatusCode());
139
+		$this->assertArrayHasKey('errors', $result);
140 140
 	}
141 141
 
142 142
 
@@ -144,20 +144,20 @@  discard block
 block discarded – undo
144 144
 	{
145 145
 		$templatePaths = \TestHelperJapi::getTemplatePaths();
146 146
 
147
-		$object = $this->getMockBuilder( '\Aimeos\Client\JsonApi\Locale\Standard' )
148
-			->setConstructorArgs( [$this->context, $this->view, $templatePaths, 'locale'] )
149
-			->setMethods( ['getItems'] )
147
+		$object = $this->getMockBuilder('\Aimeos\Client\JsonApi\Locale\Standard')
148
+			->setConstructorArgs([$this->context, $this->view, $templatePaths, 'locale'])
149
+			->setMethods(['getItems'])
150 150
 			->getMock();
151 151
 
152
-		$object->expects( $this->once() )->method( 'getItems' )
153
-			->will( $this->throwException( new \Exception() ) );
152
+		$object->expects($this->once())->method('getItems')
153
+			->will($this->throwException(new \Exception()));
154 154
 
155 155
 
156
-		$response = $object->get( $this->view->request(), $this->view->response() );
157
-		$result = json_decode( (string) $response->getBody(), true );
156
+		$response = $object->get($this->view->request(), $this->view->response());
157
+		$result = json_decode((string) $response->getBody(), true);
158 158
 
159 159
 
160
-		$this->assertEquals( 500, $response->getStatusCode() );
161
-		$this->assertArrayHasKey( 'errors', $result );
160
+		$this->assertEquals(500, $response->getStatusCode());
161
+		$this->assertArrayHasKey('errors', $result);
162 162
 	}
163 163
 }
164 164
\ No newline at end of file
Please login to merge, or discard this patch.
client/jsonapi/src/Client/JsonApi/Common/Factory/Base.php 1 patch
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 	 * @param string $classname Full name of the class for which the object should be returned
32 32
 	 * @param \Aimeos\Client\JsonApi\Iface|null $client JSON API client object
33 33
 	 */
34
-	public static function injectClient( $classname, \Aimeos\Client\JsonApi\Iface $client = null )
34
+	public static function injectClient($classname, \Aimeos\Client\JsonApi\Iface $client = null)
35 35
 	{
36 36
 		self::$objects[$classname] = $client;
37 37
 	}
@@ -47,8 +47,8 @@  discard block
 block discarded – undo
47 47
 	 * @param string $path Name of the client, e.g "product"
48 48
 	 * @return \Aimeos\Client\JsonApi\Iface Client object
49 49
 	 */
50
-	protected static function addClientDecorators( \Aimeos\Client\JsonApi\Iface $client,
51
-		\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MW\View\Iface $view, array $templatePaths, $path )
50
+	protected static function addClientDecorators(\Aimeos\Client\JsonApi\Iface $client,
51
+		\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MW\View\Iface $view, array $templatePaths, $path)
52 52
 	{
53 53
 		$config = $context->getConfig();
54 54
 
@@ -74,38 +74,38 @@  discard block
 block discarded – undo
74 74
 		 * @since 2015.12
75 75
 		 * @category Developer
76 76
 		 */
77
-		$decorators = $config->get( 'client/jsonapi/common/decorators/default', array() );
77
+		$decorators = $config->get('client/jsonapi/common/decorators/default', array());
78 78
 
79
-		if( $path !== null && is_string( $path ) )
79
+		if ($path !== null && is_string($path))
80 80
 		{
81
-			$dpath = trim( $path, '/' );
82
-			$dpath = ( $dpath !== '' ? $dpath . '/' : $dpath );
81
+			$dpath = trim($path, '/');
82
+			$dpath = ($dpath !== '' ? $dpath . '/' : $dpath);
83 83
 
84
-			$excludes = $config->get( 'client/jsonapi/' . $dpath . 'decorators/excludes', array() );
85
-			$localClass = str_replace( ' ', '\\', ucwords( str_replace( '/', ' ', $path ) ) );
84
+			$excludes = $config->get('client/jsonapi/' . $dpath . 'decorators/excludes', array());
85
+			$localClass = str_replace(' ', '\\', ucwords(str_replace('/', ' ', $path)));
86 86
 
87
-			foreach( $decorators as $key => $name )
87
+			foreach ($decorators as $key => $name)
88 88
 			{
89
-				if( in_array( $name, $excludes ) ) {
90
-					unset( $decorators[$key] );
89
+				if (in_array($name, $excludes)) {
90
+					unset($decorators[$key]);
91 91
 				}
92 92
 			}
93 93
 
94 94
 			$classprefix = '\\Aimeos\\Client\\JsonApi\\Common\\Decorator\\';
95
-			$decorators = $config->get( 'client/jsonapi/' . $dpath . 'decorators/global', array() );
96
-			$client = self::addDecorators( $client, $decorators, $classprefix, $context, $view, $templatePaths, $path );
95
+			$decorators = $config->get('client/jsonapi/' . $dpath . 'decorators/global', array());
96
+			$client = self::addDecorators($client, $decorators, $classprefix, $context, $view, $templatePaths, $path);
97 97
 
98
-			if( !empty( $path ) )
98
+			if (!empty($path))
99 99
 			{
100
-				$classprefix = '\\Aimeos\\Client\\JsonApi\\' . ucfirst( $localClass ) . '\\Decorator\\';
101
-				$decorators = $config->get( 'client/jsonapi/' . $dpath . 'decorators/local', array() );
102
-				$client = self::addDecorators( $client, $decorators, $classprefix, $context, $view, $templatePaths, $path );
100
+				$classprefix = '\\Aimeos\\Client\\JsonApi\\' . ucfirst($localClass) . '\\Decorator\\';
101
+				$decorators = $config->get('client/jsonapi/' . $dpath . 'decorators/local', array());
102
+				$client = self::addDecorators($client, $decorators, $classprefix, $context, $view, $templatePaths, $path);
103 103
 			}
104 104
 		}
105 105
 		else
106 106
 		{
107 107
 			$classprefix = '\\Aimeos\\Client\\JsonApi\\Common\\Decorator\\';
108
-			$client = self::addDecorators( $client, $decorators, $classprefix, $context, $view, $templatePaths, $path );
108
+			$client = self::addDecorators($client, $decorators, $classprefix, $context, $view, $templatePaths, $path);
109 109
 		}
110 110
 
111 111
 		return $client;
@@ -124,29 +124,29 @@  discard block
 block discarded – undo
124 124
 	 * @param string $path Name of the client, e.g "product"
125 125
 	 * @return \Aimeos\Client\JsonApi\Iface Client object
126 126
 	 */
127
-	protected static function addDecorators( \Aimeos\Client\JsonApi\Iface $client, array $decorators, $classprefix,
128
-			\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MW\View\Iface $view, $templatePaths, $path )
127
+	protected static function addDecorators(\Aimeos\Client\JsonApi\Iface $client, array $decorators, $classprefix,
128
+			\Aimeos\MShop\Context\Item\Iface $context, \Aimeos\MW\View\Iface $view, $templatePaths, $path)
129 129
 	{
130 130
 		$iface = '\\Aimeos\\Client\\JsonApi\\Common\\Decorator\\Iface';
131 131
 
132
-		foreach( $decorators as $name )
132
+		foreach ($decorators as $name)
133 133
 		{
134
-			if( ctype_alnum( $name ) === false )
134
+			if (ctype_alnum($name) === false)
135 135
 			{
136
-				$classname = is_string( $name ) ? $classprefix . $name : '<not a string>';
137
-				throw new \Aimeos\Client\JsonApi\Exception( sprintf( 'Invalid class name "%1$s"', $classname ), 404 );
136
+				$classname = is_string($name) ? $classprefix . $name : '<not a string>';
137
+				throw new \Aimeos\Client\JsonApi\Exception(sprintf('Invalid class name "%1$s"', $classname), 404);
138 138
 			}
139 139
 
140 140
 			$classname = $classprefix . $name;
141 141
 
142
-			if( class_exists( $classname ) === false ) {
143
-				throw new \Aimeos\Client\JsonApi\Exception( sprintf( 'Class "%1$s" not found', $classname ), 404 );
142
+			if (class_exists($classname) === false) {
143
+				throw new \Aimeos\Client\JsonApi\Exception(sprintf('Class "%1$s" not found', $classname), 404);
144 144
 			}
145 145
 
146
-			$client = new $classname( $client, $context, $view, $templatePaths, $path );
146
+			$client = new $classname($client, $context, $view, $templatePaths, $path);
147 147
 
148
-			if( !( $client instanceof $iface ) ) {
149
-				throw new \Aimeos\Client\JsonApi\Exception( sprintf( 'Class "%1$s" does not implement "%2$s"', $classname, $iface ), 404 );
148
+			if (!($client instanceof $iface)) {
149
+				throw new \Aimeos\Client\JsonApi\Exception(sprintf('Class "%1$s" does not implement "%2$s"', $classname, $iface), 404);
150 150
 			}
151 151
 		}
152 152
 
@@ -165,21 +165,21 @@  discard block
 block discarded – undo
165 165
 	 * @param string $path Name of the client, e.g "product"
166 166
 	 * @return \Aimeos\Client\JsonApi\Iface Client object
167 167
 	 */
168
-	protected static function createClientBase( $classname, $interface, \Aimeos\MShop\Context\Item\Iface $context,
169
-		\Aimeos\MW\View\Iface $view, array $templatePaths, $path )
168
+	protected static function createClientBase($classname, $interface, \Aimeos\MShop\Context\Item\Iface $context,
169
+		\Aimeos\MW\View\Iface $view, array $templatePaths, $path)
170 170
 	{
171
-		if( isset( self::$objects[$classname] ) ) {
171
+		if (isset(self::$objects[$classname])) {
172 172
 			return self::$objects[$classname];
173 173
 		}
174 174
 
175
-		if( class_exists( $classname ) === false ) {
176
-			throw new \Aimeos\Client\JsonApi\Exception( sprintf( 'Class "%1$s" not found', $classname ), 404 );
175
+		if (class_exists($classname) === false) {
176
+			throw new \Aimeos\Client\JsonApi\Exception(sprintf('Class "%1$s" not found', $classname), 404);
177 177
 		}
178 178
 
179
-		$client = new $classname( $context, $view, $templatePaths, $path );
179
+		$client = new $classname($context, $view, $templatePaths, $path);
180 180
 
181
-		if( !( $client instanceof $interface ) ) {
182
-			throw new \Aimeos\Client\JsonApi\Exception( sprintf( 'Class "%1$s" does not implement "%2$s"', $classname, $interface ), 500 );
181
+		if (!($client instanceof $interface)) {
182
+			throw new \Aimeos\Client\JsonApi\Exception(sprintf('Class "%1$s" does not implement "%2$s"', $classname, $interface), 500);
183 183
 		}
184 184
 
185 185
 		return $client;
Please login to merge, or discard this patch.
client/jsonapi/src/Client/JsonApi/Common/Factory/Iface.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -28,5 +28,5 @@
 block discarded – undo
28 28
 	 * @param string|null $name Name of the client implementation ("Standard" if null)
29 29
 	 * @return \Aimeos\Client\JsonApi\Iface Client Interface
30 30
 	 */
31
-	public static function createClient( \Aimeos\MShop\Context\Item\Iface $context, array $templatePaths, $path, $name = null );
31
+	public static function createClient(\Aimeos\MShop\Context\Item\Iface $context, array $templatePaths, $path, $name = null);
32 32
 }
Please login to merge, or discard this patch.