Completed
Push — master ( 75d10e...433dcb )
by Aimeos
01:39
created

BaseTest::testGet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
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
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 testGet()
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( 'get' )
116
			->will( $this->returnValue( $item ) );
117
118
		$this->assertInstanceOf( $expected, $this->object->get( 1, ['text'] ) );
119
	}
120
121
122
	public function testFind()
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( 'find' )
128
			->will( $this->returnValue( $item ) );
129
130
		$this->assertInstanceOf( $expected, $this->object->find( 'test', ['text'] ) );
131
	}
132
133
134
	public function testOneOf()
135
	{
136
		$expected = \Aimeos\Controller\Frontend\Product\Iface::class;
137
138
		$this->stub->expects( $this->once() )->method( 'oneOf' )
139
			->will( $this->returnValue( $this->stub ) );
140
141
		$this->assertInstanceOf( $expected, $this->object->oneOf( [1, 2] ) );
142
	}
143
144
145
	public function testParse()
146
	{
147
		$expected = \Aimeos\Controller\Frontend\Product\Iface::class;
148
149
		$this->stub->expects( $this->once() )->method( 'parse' )
150
			->will( $this->returnValue( $this->stub ) );
151
152
		$this->assertInstanceOf( $expected, $this->object->parse( [] ) );
153
	}
154
155
156
	public function testProduct()
157
	{
158
		$expected = \Aimeos\Controller\Frontend\Product\Iface::class;
159
160
		$this->stub->expects( $this->once() )->method( 'product' )
161
			->will( $this->returnValue( $this->stub ) );
162
163
		$this->assertInstanceOf( $expected, $this->object->product( [1, 3] ) );
164
	}
165
166
167
	public function testSearch()
168
	{
169
		$item = \Aimeos\MShop::create( $this->context, 'product' )->createItem();
170
		$expected = \Aimeos\MShop\Product\Item\Iface::class;
0 ignored issues
show
Unused Code introduced by
$expected is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
171
		$total = 0;
172
173
		$this->stub->expects( $this->once() )->method( 'search' )
174
			->will( $this->returnValue( [$item] ) );
175
176
		$this->assertEquals( [$item], $this->object->search( ['text'], $total ) );
177
	}
178
179
180
	public function testSlice()
181
	{
182
		$expected = \Aimeos\Controller\Frontend\Product\Iface::class;
183
184
		$this->stub->expects( $this->once() )->method( 'slice' )
185
			->will( $this->returnValue( $this->stub ) );
186
187
		$this->assertInstanceOf( $expected, $this->object->slice( 0, 100 ) );
188
	}
189
190
191
	public function testSort()
192
	{
193
		$expected = \Aimeos\Controller\Frontend\Product\Iface::class;
194
195
		$this->stub->expects( $this->once() )->method( 'sort' )
196
			->will( $this->returnValue( $this->stub ) );
197
198
		$this->assertInstanceOf( $expected, $this->object->sort( 'code' ) );
199
	}
200
201
202
	public function testSupplier()
203
	{
204
		$expected = \Aimeos\Controller\Frontend\Product\Iface::class;
205
206
		$this->stub->expects( $this->once() )->method( 'supplier' )
207
			->will( $this->returnValue( $this->stub ) );
208
209
		$this->assertInstanceOf( $expected, $this->object->supplier( [1], 'default' ) );
210
	}
211
212
213
	public function testText()
214
	{
215
		$expected = \Aimeos\Controller\Frontend\Product\Iface::class;
216
217
		$this->stub->expects( $this->once() )->method( 'text' )
218
			->will( $this->returnValue( $this->stub ) );
219
220
		$this->assertInstanceOf( $expected, $this->object->text( 'test' ) );
221
	}
222
223
224
	public function testGetController()
225
	{
226
		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] );
227
228
		$this->assertSame( $this->stub, $result );
229
	}
230
231
232
	protected function access( $name )
233
	{
234
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Product\Decorator\Base::class );
235
		$method = $class->getMethod( $name );
236
		$method->setAccessible( true );
237
238
		return $method;
239
	}
240
}
241