Passed
Push — master ( 154e9f...c95a25 )
by Aimeos
03:44
created

StandardTest::testDeleteJqadmException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 7
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * @license LGPLv3, http://opensource.org/licenses/LGPL-3.0
5
 * @copyright Aimeos (aimeos.org), 2017-2018
6
 */
7
8
9
namespace Aimeos\Admin\JQAdm\Supplier;
10
11
12
class StandardTest extends \PHPUnit\Framework\TestCase
0 ignored issues
show
Bug introduced by
The type PHPUnit\Framework\TestCase was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
{
14
	private $context;
15
	private $object;
16
	private $view;
17
18
19
	protected function setUp()
20
	{
21
		$this->view = \TestHelperJqadm::getView();
22
		$this->context = \TestHelperJqadm::getContext();
23
24
		$this->object = new \Aimeos\Admin\JQAdm\Supplier\Standard( $this->context );
25
		$this->object = new \Aimeos\Admin\JQAdm\Common\Decorator\Page( $this->object, $this->context );
26
		$this->object->setAimeos( \TestHelperJqadm::getAimeos() );
27
		$this->object->setView( $this->view );
28
	}
29
30
31
	protected function tearDown()
32
	{
33
		unset( $this->object, $this->view, $this->context );
34
	}
35
36
37
	public function testCreate()
38
	{
39
		$this->object->create();
40
	}
41
42
43
	public function testCreateException()
44
	{
45
		$object = $this->getClientMock( 'getSubClients' );
46
47
		$object->expects( $this->once() )->method( 'getSubClients' )
48
			->will( $this->throwException( new \RuntimeException() ) );
49
50
		$object->create();
51
	}
52
53
54
	public function testCreateMShopException()
55
	{
56
		$object = $this->getClientMock( 'getSubClients' );
57
58
		$object->expects( $this->once() )->method( 'getSubClients' )
59
			->will( $this->throwException( new \Aimeos\MShop\Exception() ) );
60
61
		$object->create();
62
	}
63
64
65
	public function testCopy()
66
	{
67
		$manager = \Aimeos\MShop::create( $this->context, 'supplier' );
68
69
		$param = ['site' => 'unittest', 'id' => $manager->findItem( 'unitCode001' )->getId()];
70
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param );
71
		$this->view->addHelper( 'param', $helper );
72
73
		$result = $this->object->copy();
74
75
		$this->assertContains( 'unitSupplier001', $result );
76
	}
77
78
79
	public function testCopyException()
80
	{
81
		$object = $this->getClientMock( 'getSubClients' );
82
83
		$object->expects( $this->once() )->method( 'getSubClients' )
84
			->will( $this->throwException( new \RuntimeException() ) );
85
86
		$object->copy();
87
	}
88
89
90
	public function testCopyMShopException()
91
	{
92
		$object = $this->getClientMock( 'getSubClients' );
93
94
		$object->expects( $this->once() )->method( 'getSubClients' )
95
			->will( $this->throwException( new \Aimeos\MShop\Exception() ) );
96
97
		$object->copy();
98
	}
99
100
101
	public function testDelete()
102
	{
103
		$this->assertNull( $this->getClientMock( 'getSubClients' )->delete() );
104
	}
105
106
107
	public function testDeleteJqadmException()
108
	{
109
		$object = $this->getClientMock( ['getSubClients', 'search'] );
110
111
		$object->expects( $this->once() )->method( 'search' );
112
113
		$object->delete();
114
	}
115
116
117
	public function testDeleteException()
118
	{
119
		$object = $this->getClientMock( ['getSubClients', 'search'] );
120
121
		$object->expects( $this->once() )->method( 'getSubClients' )
122
			->will( $this->throwException( new \RuntimeException() ) );
123
		$object->expects( $this->once() )->method( 'search' );
124
125
		$object->delete();
126
	}
127
128
129
	public function testDeleteMShopException()
130
	{
131
		$object = $this->getClientMock( ['getSubClients', 'search'] );
132
133
		$object->expects( $this->once() )->method( 'getSubClients' )
134
			->will( $this->throwException( new \Aimeos\MShop\Exception() ) );
135
		$object->expects( $this->once() )->method( 'search' );
136
137
		$object->delete();
138
	}
139
140
141
	public function testGet()
142
	{
143
		$manager = \Aimeos\MShop::create( $this->context, 'supplier' );
144
145
		$param = ['site' => 'unittest', 'id' => $manager->findItem( 'unitCode001' )->getId()];
146
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param );
147
		$this->view->addHelper( 'param', $helper );
148
149
		$result = $this->object->get();
150
151
		$this->assertContains( 'unitSupplier001', $result );
152
	}
153
154
155
	public function testGetException()
156
	{
157
		$object = $this->getClientMock( 'getSubClients' );
158
159
		$object->expects( $this->once() )->method( 'getSubClients' )
160
			->will( $this->throwException( new \RuntimeException() ) );
161
162
		$object->get();
163
	}
164
165
166
	public function testGetMShopException()
167
	{
168
		$object = $this->getClientMock( 'getSubClients' );
169
170
		$object->expects( $this->once() )->method( 'getSubClients' )
171
			->will( $this->throwException( new \Aimeos\MShop\Exception() ) );
172
173
		$object->get();
174
	}
175
176
177
	public function testGetViewException()
178
	{
179
		$object = new \Aimeos\Admin\JQAdm\Supplier\Standard( $this->context, [] );
0 ignored issues
show
Unused Code introduced by
The call to Aimeos\Admin\JQAdm\Suppl...Standard::__construct() has too many arguments starting with array(). ( Ignorable by Annotation )

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

179
		$object = /** @scrutinizer ignore-call */ new \Aimeos\Admin\JQAdm\Supplier\Standard( $this->context, [] );

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
180
181
		$this->setExpectedException( \Aimeos\Admin\JQAdm\Exception::class );
182
		$object->getView();
183
	}
184
185
186
	public function testSave()
187
	{
188
		$manager = \Aimeos\MShop::create( $this->context, 'supplier' );
189
190
		$param = array(
191
			'site' => 'unittest',
192
			'item' => array(
193
				'supplier.id' => '',
194
				'supplier.code' => 'jqadm@test',
195
				'supplier.label' => 'JQAdm test',
196
				'supplier.status' => '1',
197
			),
198
		);
199
200
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param );
201
		$this->view->addHelper( 'param', $helper );
202
203
		$this->object->save();
204
205
		$manager->deleteItem( $manager->findItem( 'jqadm@test' )->getId() );
206
	}
207
208
209
	public function testSaveException()
210
	{
211
		$object = $this->getClientMock( 'fromArray' );
212
213
		$object->expects( $this->once() )->method( 'fromArray' )
214
			->will( $this->throwException( new \RuntimeException() ) );
215
216
		$object->save();
217
	}
218
219
220
	public function testSaveMShopException()
221
	{
222
		$object = $this->getClientMock( 'fromArray' );
223
224
		$object->expects( $this->once() )->method( 'fromArray' )
225
			->will( $this->throwException( new \RuntimeException() ) );
226
227
		$object->save();
228
	}
229
230
231
	public function testSaveJQAdmException()
232
	{
233
		$object = $this->getClientMock( 'fromArray' );
234
235
		$object->expects( $this->once() )->method( 'fromArray' )
236
			->will( $this->throwException( new \RuntimeException() ) );
237
238
		$object->save();
239
	}
240
241
242
	public function testSearch()
243
	{
244
		$param = array(
245
			'site' => 'unittest', 'lang' => 'de',
246
			'filter' => array(
247
				'key' => array( 0 => 'supplier.code' ),
248
				'op' => array( 0 => '==' ),
249
				'val' => array( 0 => 'unitCode001' ),
250
			),
251
			'sort' => array( 'supplier.label', '-supplier.id' ),
252
		);
253
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $this->view, $param );
254
		$this->view->addHelper( 'param', $helper );
255
256
		$result = $this->object->search();
257
258
		$this->assertContains( '>unitCode001<', $result );
259
	}
260
261
262
	public function testSearchException()
263
	{
264
		$object = $this->getClientMock( 'initCriteria' );
265
266
		$object->expects( $this->once() )->method( 'initCriteria' )
267
			->will( $this->throwException( new \RuntimeException() ) );
268
269
		$object->search();
270
	}
271
272
273
	public function testSearchMShopException()
274
	{
275
		$object = $this->getClientMock( 'initCriteria' );
276
277
		$object->expects( $this->once() )->method( 'initCriteria' )
278
			->will( $this->throwException( new \Aimeos\MShop\Exception() ) );
279
280
		$object->search();
281
	}
282
283
284
	public function testGetSubClient()
285
	{
286
		$result = $this->object->getSubClient( 'address' );
287
		$this->assertInstanceOf( \Aimeos\Admin\JQAdm\Iface::class, $result );
288
	}
289
290
291
	public function testGetSubClientInvalid()
292
	{
293
		$this->setExpectedException( \Aimeos\Admin\JQAdm\Exception::class );
294
		$this->object->getSubClient( '$unknown$' );
295
	}
296
297
298
	public function testGetSubClientUnknown()
299
	{
300
		$this->setExpectedException( \Aimeos\Admin\JQAdm\Exception::class );
301
		$this->object->getSubClient( 'unknown' );
302
	}
303
304
305
	public function getClientMock( $methods )
306
	{
307
		$object = $this->getMockBuilder( \Aimeos\Admin\JQAdm\Supplier\Standard::class )
308
			->setConstructorArgs( array( $this->context, \TestHelperJqadm::getTemplatePaths() ) )
309
			->setMethods( (array) $methods )
310
			->getMock();
311
312
		$object->setAimeos( \TestHelperJqadm::getAimeos() );
313
		$object->setView( $this->getViewNoRender() );
314
315
		return $object;
316
	}
317
318
319
	protected function getViewNoRender()
320
	{
321
		$view = $this->getMockBuilder( \Aimeos\MW\View\Standard::class )
322
			->setConstructorArgs( array( [] ) )
323
			->setMethods( array( 'render', 'config' ) )
324
			->getMock();
325
326
		$manager = \Aimeos\MShop::create( $this->context, 'supplier' );
327
328
		$param = ['site' => 'unittest', 'id' => $manager->findItem( 'unitCode001' )->getId()];
329
		$helper = new \Aimeos\MW\View\Helper\Param\Standard( $view, $param );
330
		$view->addHelper( 'param', $helper );
331
332
		$helper = new \Aimeos\MW\View\Helper\Access\Standard( $view, [] );
333
		$view->addHelper( 'access', $helper );
334
335
		return $view;
336
	}
337
}
338