BaseTest::testFind()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 9
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-2025
6
 */
7
8
9
namespace Aimeos\Controller\Frontend\Product\Decorator;
10
11
12
class Example extends Base
13
{
14
}
15
16
17
class BaseTest extends \PHPUnit\Framework\TestCase
18
{
19
	private $context;
20
	private $object;
21
	private $stub;
22
23
24
	protected function setUp() : void
25
	{
26
		$this->context = \TestHelper::context();
27
28
		$this->stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Product\Standard::class )
29
			->disableOriginalConstructor()
30
			->getMock();
31
32
		$this->object = new \Aimeos\Controller\Frontend\Product\Decorator\Example( $this->stub, $this->context );
33
	}
34
35
36
	protected function tearDown() : void
37
	{
38
		unset( $this->context, $this->object, $this->stub );
39
	}
40
41
42
	public function testCall()
43
	{
44
		$stub = $this->getMockBuilder( \Aimeos\Controller\Frontend\Product\Standard::class )
45
			->disableOriginalConstructor()
46
			->onlyMethods( ['__call'] )
47
			->getMock();
48
49
		$object = new \Aimeos\Controller\Frontend\Product\Decorator\Example( $stub, $this->context );
50
51
		$stub->expects( $this->once() )->method( '__call' )->willReturn( true );
52
53
		$this->assertTrue( $object->invalid() );
0 ignored issues
show
Bug introduced by
The method invalid() does not exist on Aimeos\Controller\Fronte...oduct\Decorator\Example. Since you implemented __call, consider adding a @method annotation. ( Ignorable by Annotation )

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

53
		$this->assertTrue( $object->/** @scrutinizer ignore-call */ invalid() );
Loading history...
54
	}
55
56
57
	public function testAggregate()
58
	{
59
		$this->stub->expects( $this->once() )->method( 'aggregate' )
60
			->willReturn( map() );
61
62
		$this->assertEquals( [], $this->object->aggregate( 'test' )->toArray() );
63
	}
64
65
66
	public function testAllOf()
67
	{
68
		$this->assertSame( $this->object, $this->object->allOf( [1, 2] ) );
69
	}
70
71
72
	public function testCategory()
73
	{
74
		$level = \Aimeos\MW\Tree\Manager\Base::LEVEL_TREE;
75
		$this->assertSame( $this->object, $this->object->category( 1, 'default', $level ) );
76
	}
77
78
79
	public function testCompare()
80
	{
81
		$this->assertSame( $this->object, $this->object->compare( '==', 'product.code', 'test' ) );
82
	}
83
84
85
	public function testFind()
86
	{
87
		$item = \Aimeos\MShop::create( $this->context, 'product' )->create();
88
		$expected = \Aimeos\MShop\Product\Item\Iface::class;
89
90
		$this->stub->expects( $this->once() )->method( 'find' )
91
			->willReturn( $item );
92
93
		$this->assertInstanceOf( $expected, $this->object->find( 'test', ['text'] ) );
94
	}
95
96
97
	public function testFunction()
98
	{
99
		$this->stub->expects( $this->once() )->method( 'function' )
100
			->willReturn( 'product:has("domain","type","refid")' );
101
102
		$str = $this->object->function( 'product:has', ['domain', 'type', 'refid'] );
103
		$this->assertEquals( 'product:has("domain","type","refid")', $str );
104
	}
105
106
107
	public function testGet()
108
	{
109
		$item = \Aimeos\MShop::create( $this->context, 'product' )->create();
110
		$expected = \Aimeos\MShop\Product\Item\Iface::class;
111
112
		$this->stub->expects( $this->once() )->method( 'get' )
113
			->willReturn( $item );
114
115
		$this->assertInstanceOf( $expected, $this->object->get( 1, ['text'] ) );
116
	}
117
118
119
	public function testHas()
120
	{
121
		$this->assertSame( $this->object, $this->object->has( 'attribute', 'default', -1 ) );
122
	}
123
124
125
	public function testOneOf()
126
	{
127
		$this->assertSame( $this->object, $this->object->oneOf( [1, 2] ) );
128
	}
129
130
131
	public function testParse()
132
	{
133
		$this->assertSame( $this->object, $this->object->parse( [] ) );
134
	}
135
136
137
	public function testPrice()
138
	{
139
		$this->assertSame( $this->object, $this->object->price( 0 ) );
140
	}
141
142
143
	public function testProduct()
144
	{
145
		$this->assertSame( $this->object, $this->object->product( [1, 3] ) );
146
	}
147
148
149
	public function testProperty()
150
	{
151
		$this->assertSame( $this->object, $this->object->property( 'test', 'value' ) );
152
	}
153
154
155
	public function testRadius()
156
	{
157
		$this->assertSame( $this->object, $this->object->radius( [] ) );
158
	}
159
160
161
	public function testResolve()
162
	{
163
		$item = \Aimeos\MShop::create( $this->context, 'product' )->create();
164
165
		$this->stub->expects( $this->once() )->method( 'resolve' )
166
			->willReturn( $item );
167
168
		$this->assertEquals( $item, $this->object->resolve( 'test' ) );
169
	}
170
171
172
	public function testSearch()
173
	{
174
		$total = 0;
175
		$item = \Aimeos\MShop::create( $this->context, 'product' )->create();
176
177
		$this->stub->expects( $this->once() )->method( 'search' )
178
			->willReturn( map( [$item] ) );
179
180
		$this->assertEquals( [$item], $this->object->search( $total )->toArray() );
181
	}
182
183
184
	public function testSlice()
185
	{
186
		$this->assertSame( $this->object, $this->object->slice( 0, 100 ) );
187
	}
188
189
190
	public function testSort()
191
	{
192
		$this->assertSame( $this->object, $this->object->sort( 'code' ) );
193
	}
194
195
196
	public function testSupplier()
197
	{
198
		$this->assertSame( $this->object, $this->object->supplier( [1], 'default' ) );
199
	}
200
201
202
	public function testText()
203
	{
204
		$this->assertSame( $this->object, $this->object->text( 'test' ) );
205
	}
206
207
208
	public function testUses()
209
	{
210
		$this->assertSame( $this->object, $this->object->uses( ['text'] ) );
211
	}
212
213
214
	public function testGetController()
215
	{
216
		$result = $this->access( 'getController' )->invokeArgs( $this->object, [] );
217
218
		$this->assertSame( $this->stub, $result );
219
	}
220
221
222
	protected function access( $name )
223
	{
224
		$class = new \ReflectionClass( \Aimeos\Controller\Frontend\Product\Decorator\Base::class );
225
		$method = $class->getMethod( $name );
226
		$method->setAccessible( true );
227
228
		return $method;
229
	}
230
}
231