Passed
Push — master ( 6cf50b...92e939 )
by Aimeos
01:45
created

BaseTest::testHas()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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\Controller\Frontend\Product\Decorator;
10
11
12
class BaseTest 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 $stub;
17
18
19
	protected function setUp()
20
	{
21
		$this->context = \TestHelperFrontend::getContext();
22
23
		$this->stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Product\Standard::class )
24
			->disableOriginalConstructor()
25
			->getMock();
26
27
		$this->object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Product\Decorator\Base::class )
28
			->setConstructorArgs( [$this->stub, $this->context] )
29
			->getMockForAbstractClass();
30
	}
31
32
33
	protected function tearDown()
34
	{
35
		unset( $this->context, $this->object, $this->stub );
36
	}
37
38
39
	public function testConstructException()
40
	{
41
		$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Iface::class )->getMock();
42
43
		$this->setExpectedException( \Aimeos\MW\Common\Exception::class );
44
45
		$this->getMockBuilder( \Aimeos\Controller\Frontend\Product\Decorator\Base::class )
46
			->setConstructorArgs( [$stub, $this->context] )
47
			->getMockForAbstractClass();
48
	}
49
50
51
	public function testCall()
52
	{
53
		$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Product\Standard::class )
54
			->disableOriginalConstructor()
55
			->setMethods( ['invalid'] )
56
			->getMock();
57
58
		$object = $this->getMockBuilder( \Aimeos\Controller\Frontend\Product\Decorator\Base::class )
59
			->setConstructorArgs( [$stub, $this->context] )
60
			->getMockForAbstractClass();
61
62
		$stub->expects( $this->once() )->method( 'invalid' )->will( $this->returnValue( true ) );
63
64
		$this->assertTrue( $object->invalid() );
65
	}
66
67
68
	public function testAggregate()
69
	{
70
		$this->stub->expects( $this->once() )->method( 'aggregate' )
71
			->will( $this->returnValue( [] ) );
72
73
		$this->assertEquals( [], $this->object->aggregate( 'test' ) );
74
	}
75
76
77
	public function testAllOf()
78
	{
79
		$expected = \Aimeos\Controller\Frontend\Product\Iface::class;
80
81
		$this->stub->expects( $this->once() )->method( 'allOf' )
82
			->will( $this->returnValue( $this->stub ) );
83
84
		$this->assertInstanceOf( $expected, $this->object->allOf( [1, 2] ) );
85
	}
86
87
88
	public function testCategory()
89
	{
90
		$expected = \Aimeos\Controller\Frontend\Product\Iface::class;
91
92
		$this->stub->expects( $this->once() )->method( 'category' )
93
			->will( $this->returnValue( $this->stub ) );
94
95
		$this->assertInstanceOf( $expected, $this->object->category( 1, 'default', \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE ) );
96
	}
97
98
99
	public function testCompare()
100
	{
101
		$expected = \Aimeos\Controller\Frontend\Product\Iface::class;
102
103
		$this->stub->expects( $this->once() )->method( 'compare' )
104
			->will( $this->returnValue( $this->stub ) );
105
106
		$this->assertInstanceOf( $expected, $this->object->compare( '==', 'product.code', 'test' ) );
107
	}
108
109
110
	public function testFind()
111
	{
112
		$item = \Aimeos\MShop::create( $this->context, 'product' )->createItem();
113
		$expected = \Aimeos\MShop\Product\Item\Iface::class;
114
115
		$this->stub->expects( $this->once() )->method( 'find' )
116
			->will( $this->returnValue( $item ) );
117
118
		$this->assertInstanceOf( $expected, $this->object->find( 'test', ['text'] ) );
119
	}
120
121
122
	public function testGet()
123
	{
124
		$item = \Aimeos\MShop::create( $this->context, 'product' )->createItem();
125
		$expected = \Aimeos\MShop\Product\Item\Iface::class;
126
127
		$this->stub->expects( $this->once() )->method( 'get' )
128
			->will( $this->returnValue( $item ) );
129
130
		$this->assertInstanceOf( $expected, $this->object->get( 1, ['text'] ) );
131
	}
132
133
134
	public function testHas()
135
	{
136
		$expected = \Aimeos\Controller\Frontend\Product\Iface::class;
137
138
		$this->stub->expects( $this->once() )->method( 'has' )
139
			->will( $this->returnValue( $this->stub ) );
140
141
		$this->assertInstanceOf( $expected, $this->object->has( 'attribute', 'default', -1 ) );
142
	}
143
144
145
	public function testOneOf()
146
	{
147
		$expected = \Aimeos\Controller\Frontend\Product\Iface::class;
148
149
		$this->stub->expects( $this->once() )->method( 'oneOf' )
150
			->will( $this->returnValue( $this->stub ) );
151
152
		$this->assertInstanceOf( $expected, $this->object->oneOf( [1, 2] ) );
153
	}
154
155
156
	public function testParse()
157
	{
158
		$expected = \Aimeos\Controller\Frontend\Product\Iface::class;
159
160
		$this->stub->expects( $this->once() )->method( 'parse' )
161
			->will( $this->returnValue( $this->stub ) );
162
163
		$this->assertInstanceOf( $expected, $this->object->parse( [] ) );
164
	}
165
166
167
	public function testProduct()
168
	{
169
		$expected = \Aimeos\Controller\Frontend\Product\Iface::class;
170
171
		$this->stub->expects( $this->once() )->method( 'product' )
172
			->will( $this->returnValue( $this->stub ) );
173
174
		$this->assertInstanceOf( $expected, $this->object->product( [1, 3] ) );
175
	}
176
177
178
	public function testProperty()
179
	{
180
		$expected = \Aimeos\Controller\Frontend\Product\Iface::class;
181
182
		$this->stub->expects( $this->once() )->method( 'property' )
183
			->will( $this->returnValue( $this->stub ) );
184
185
		$this->assertInstanceOf( $expected, $this->object->property( 'test', 'value' ) );
186
	}
187
188
189
	public function testSearch()
190
	{
191
		$item = \Aimeos\MShop::create( $this->context, 'product' )->createItem();
192
		$expected = \Aimeos\MShop\Product\Item\Iface::class;
0 ignored issues
show
Unused Code introduced by
The assignment to $expected is dead and can be removed.
Loading history...
193
		$total = 0;
194
195
		$this->stub->expects( $this->once() )->method( 'search' )
196
			->will( $this->returnValue( [$item] ) );
197
198
		$this->assertEquals( [$item], $this->object->search( ['text'], $total ) );
199
	}
200
201
202
	public function testSlice()
203
	{
204
		$expected = \Aimeos\Controller\Frontend\Product\Iface::class;
205
206
		$this->stub->expects( $this->once() )->method( 'slice' )
207
			->will( $this->returnValue( $this->stub ) );
208
209
		$this->assertInstanceOf( $expected, $this->object->slice( 0, 100 ) );
210
	}
211
212
213
	public function testSort()
214
	{
215
		$expected = \Aimeos\Controller\Frontend\Product\Iface::class;
216
217
		$this->stub->expects( $this->once() )->method( 'sort' )
218
			->will( $this->returnValue( $this->stub ) );
219
220
		$this->assertInstanceOf( $expected, $this->object->sort( 'code' ) );
221
	}
222
223
224
	public function testSupplier()
225
	{
226
		$expected = \Aimeos\Controller\Frontend\Product\Iface::class;
227
228
		$this->stub->expects( $this->once() )->method( 'supplier' )
229
			->will( $this->returnValue( $this->stub ) );
230
231
		$this->assertInstanceOf( $expected, $this->object->supplier( [1], 'default' ) );
232
	}
233
234
235
	public function testText()
236
	{
237
		$expected = \Aimeos\Controller\Frontend\Product\Iface::class;
238
239
		$this->stub->expects( $this->once() )->method( 'text' )
240
			->will( $this->returnValue( $this->stub ) );
241
242
		$this->assertInstanceOf( $expected, $this->object->text( 'test' ) );
243
	}
244
245
246
	public function testGetController()
247
	{
248
		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] );
249
250
		$this->assertSame( $this->stub, $result );
251
	}
252
253
254
	protected function access( $name )
255
	{
256
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Product\Decorator\Base::class );
257
		$method = $class->getMethod( $name );
258
		$method->setAccessible( true );
259
260
		return $method;
261
	}
262
}
263