Total Complexity | 40 |
Total Lines | 328 |
Duplicated Lines | 0 % |
Changes | 27 | ||
Bugs | 0 | Features | 0 |
Complex classes like StandardTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use StandardTest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
12 | class StandardTest extends \PHPUnit\Framework\TestCase |
||
13 | { |
||
14 | private $object; |
||
15 | |||
16 | |||
17 | protected function setUp() : void |
||
18 | { |
||
19 | $this->context = \TestHelperFrontend::getContext(); |
||
|
|||
20 | $this->object = new \Aimeos\Controller\Frontend\Product\Standard( $this->context ); |
||
21 | } |
||
22 | |||
23 | |||
24 | protected function tearDown() : void |
||
27 | } |
||
28 | |||
29 | |||
30 | public function testAggregate() |
||
31 | { |
||
32 | $list = $this->object->aggregate( 'index.attribute.id' ); |
||
33 | |||
34 | $this->assertGreaterThan( 0, count( $list ) ); |
||
35 | } |
||
36 | |||
37 | |||
38 | public function testAllOf() |
||
39 | { |
||
40 | $manager = \Aimeos\MShop::create( $this->context, 'attribute' ); |
||
41 | |||
42 | $length = $manager->find( '30', [], 'product', 'length' )->getId(); |
||
43 | $width = $manager->find( '29', [], 'product', 'width' )->getId(); |
||
44 | |||
45 | $this->assertEquals( 1, count( $this->object->allOf( [$length, $width] )->search() ) ); |
||
46 | } |
||
47 | |||
48 | |||
49 | public function testCategory() |
||
50 | { |
||
51 | $manager = \Aimeos\MShop::create( $this->context, 'catalog' ); |
||
52 | $catId = $manager->find( 'cafe' )->getId(); |
||
53 | |||
54 | $this->assertEquals( 2, count( $this->object->category( $catId, 'promotion' )->search() ) ); |
||
55 | } |
||
56 | |||
57 | |||
58 | public function testCategoryTree() |
||
67 | } |
||
68 | |||
69 | |||
70 | public function testCompare() |
||
73 | } |
||
74 | |||
75 | |||
76 | public function testFind() |
||
82 | } |
||
83 | |||
84 | |||
85 | public function testFunction() |
||
86 | { |
||
87 | $str = $this->object->function( 'product:has', ['domain', 'type', 'refid'] ); |
||
88 | $this->assertEquals( 'product:has("domain","type","refid")', $str ); |
||
89 | } |
||
90 | |||
91 | |||
92 | public function testGet() |
||
93 | { |
||
94 | $item = \Aimeos\MShop::create( $this->context, 'product' )->find( 'U:BUNDLE' ); |
||
95 | $item = $this->object->uses( ['product'] )->get( $item->getId() ); |
||
96 | |||
97 | $this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $item ); |
||
98 | $this->assertEquals( 2, count( $item->getRefItems( 'product' ) ) ); |
||
99 | } |
||
100 | |||
101 | |||
102 | public function testHas() |
||
103 | { |
||
104 | $manager = \Aimeos\MShop::create( $this->context, 'attribute' ); |
||
105 | $attrId = $manager->find( '30', [], 'product', 'length' )->getId(); |
||
106 | |||
107 | $this->assertEquals( 1, count( $this->object->has( 'attribute', 'variant', $attrId )->search() ) ); |
||
108 | } |
||
109 | |||
110 | |||
111 | public function testOneOf() |
||
112 | { |
||
113 | $manager = \Aimeos\MShop::create( $this->context, 'attribute' ); |
||
114 | |||
115 | $length = $manager->find( '30', [], 'product', 'length' )->getId(); |
||
116 | $width = $manager->find( '30', [], 'product', 'width' )->getId(); |
||
117 | |||
118 | $this->assertEquals( 2, count( $this->object->oneOf( [$length, $width] )->search() ) ); |
||
119 | } |
||
120 | |||
121 | |||
122 | public function testOneOfList() |
||
123 | { |
||
124 | $manager = \Aimeos\MShop::create( $this->context, 'attribute' ); |
||
125 | |||
126 | $length = $manager->find( '30', [], 'product', 'length' )->getId(); |
||
127 | $width = $manager->find( '30', [], 'product', 'width' )->getId(); |
||
128 | |||
129 | $this->assertEquals( 1, count( $this->object->oneOf( [[$length], [$width]] )->search() ) ); |
||
130 | } |
||
131 | |||
132 | |||
133 | public function testParse() |
||
137 | } |
||
138 | |||
139 | |||
140 | public function testPrice() |
||
141 | { |
||
142 | $this->assertEquals( 5, count( $this->object->price( 20 )->search() ) ); |
||
143 | } |
||
144 | |||
145 | |||
146 | public function testPriceArray() |
||
149 | } |
||
150 | |||
151 | |||
152 | public function testPriceBoth() |
||
153 | { |
||
154 | $this->assertEquals( 4, count( $this->object->price( [15, 20] )->search() ) ); |
||
155 | } |
||
156 | |||
157 | |||
158 | public function testProduct() |
||
159 | { |
||
160 | $manager = \Aimeos\MShop::create( $this->context, 'product' ); |
||
161 | |||
162 | $cncId = $manager->find( 'CNC' )->getId(); |
||
163 | $cneId = $manager->find( 'CNE' )->getId(); |
||
164 | |||
165 | $this->assertEquals( 2, count( $this->object->product( [$cncId, $cneId] )->search() ) ); |
||
166 | } |
||
167 | |||
168 | |||
169 | public function testProperty() |
||
172 | } |
||
173 | |||
174 | |||
175 | public function testResolve() |
||
176 | { |
||
177 | $item = $this->object->resolve( 'Cafe-Noire-Cappuccino' ); |
||
178 | |||
179 | $this->assertInstanceOf( \Aimeos\MShop\Product\Item\Iface::class, $item ); |
||
180 | $this->assertEquals( 'Cafe Noire Cappuccino', $item->getLabel() ); |
||
181 | } |
||
182 | |||
183 | |||
184 | public function testSearch() |
||
192 | } |
||
193 | |||
194 | |||
195 | public function testSearchAll() |
||
196 | { |
||
197 | $total = 0; |
||
198 | $this->context->getConfig()->set( 'controller/frontend/product/show-all', true ); |
||
199 | $object = new \Aimeos\Controller\Frontend\Product\Standard( $this->context ); |
||
200 | |||
201 | $items = $object->search( $total ); |
||
202 | |||
203 | $this->assertEquals( 22, count( $items ) ); |
||
204 | $this->assertEquals( 22, $total ); |
||
205 | } |
||
206 | |||
207 | |||
208 | public function testSlice() |
||
209 | { |
||
210 | $this->assertEquals( 2, count( $this->object->slice( 0, 2 )->search() ) ); |
||
211 | } |
||
212 | |||
213 | |||
214 | public function testSort() |
||
215 | { |
||
216 | $this->assertEquals( 8, count( $this->object->sort( '+relevance' )->search() ) ); |
||
217 | } |
||
218 | |||
219 | |||
220 | public function testSortGeneric() |
||
221 | { |
||
222 | $this->assertEquals( 8, count( $this->object->sort( '-product.status' )->search() ) ); |
||
223 | } |
||
224 | |||
225 | |||
226 | public function testSortMultiple() |
||
227 | { |
||
228 | $this->assertEquals( 8, count( $this->object->sort( 'sort:index.text:relevance("de","test(\"\")"),product.id' )->search() ) ); |
||
229 | } |
||
230 | |||
231 | |||
232 | public function testSortCode() |
||
233 | { |
||
234 | $result = $this->object->sort( 'code' )->search(); |
||
235 | $this->assertEquals( 'ABCD', $result->first()->getCode() ); |
||
236 | } |
||
237 | |||
238 | |||
239 | public function testSortCodeDesc() |
||
240 | { |
||
241 | $result = $this->object->sort( '-code' )->search(); |
||
242 | $this->assertStringStartsWith( 'U:', $result->first()->getCode() ); |
||
243 | } |
||
244 | |||
245 | |||
246 | public function testSortCtime() |
||
247 | { |
||
248 | $this->assertEquals( 8, count( $this->object->sort( 'ctime' )->search() ) ); |
||
249 | } |
||
250 | |||
251 | |||
252 | public function testSortCtimeDesc() |
||
253 | { |
||
254 | $this->assertEquals( 8, count( $this->object->sort( '-ctime' )->search() ) ); |
||
255 | } |
||
256 | |||
257 | |||
258 | public function testSortName() |
||
259 | { |
||
260 | $result = $this->object->uses( ['text'] )->sort( 'name' )->search(); |
||
261 | $this->assertEquals( 'Cafe Noire Cappuccino', $result->first()->getName() ); |
||
262 | } |
||
263 | |||
264 | |||
265 | public function testSortNameDesc() |
||
266 | { |
||
267 | $result = $this->object->uses( ['text'] )->sort( '-name' )->search(); |
||
268 | $this->assertEquals( 'Unterproduct 1', $result->first()->getName() ); |
||
269 | } |
||
270 | |||
271 | |||
272 | public function testSortPrice() |
||
273 | { |
||
274 | $result = $this->object->uses( ['price'] )->sort( 'price' )->search(); |
||
275 | $prices = $result->first()->getRefItems( 'price', 'default', 'default' ); |
||
276 | |||
277 | $this->assertEquals( '12.00', $prices->first()->getValue() ); |
||
278 | } |
||
279 | |||
280 | |||
281 | public function testSortPriceDesc() |
||
282 | { |
||
283 | $result = $this->object->uses( ['price'] )->sort( '-price' )->search(); |
||
284 | $prices = $result->first()->getRefItems( 'price', 'default', 'default' ); |
||
285 | |||
286 | $this->assertEquals( '600.00', $prices->first()->getValue() ); |
||
287 | } |
||
288 | |||
289 | |||
290 | public function testSortRelevanceCategory() |
||
291 | { |
||
292 | $manager = \Aimeos\MShop::create( $this->context, 'catalog' ); |
||
293 | $catId = $manager->find( 'new' )->getId(); |
||
294 | |||
295 | $result = $this->object->category( $catId )->sort( 'relevance' )->search(); |
||
296 | |||
297 | $this->assertEquals( 3, count( $result ) ); |
||
298 | $this->assertEquals( 'CNE', $result->first()->getCode() ); |
||
299 | $this->assertEquals( 'U:BUNDLE', $result->last()->getCode() ); |
||
300 | } |
||
301 | |||
302 | |||
303 | public function testSortRelevanceSupplier() |
||
304 | { |
||
305 | $manager = \Aimeos\MShop::create( $this->context, 'supplier' ); |
||
306 | $supId = $manager->find( 'unitSupplier001' )->getId(); |
||
307 | |||
308 | $result = $this->object->supplier( $supId )->sort( 'relevance' )->search(); |
||
309 | |||
310 | $this->assertEquals( 2, count( $result ) ); |
||
311 | $this->assertEquals( 'CNC', $result->first()->getCode() ); |
||
312 | $this->assertEquals( 'CNE', $result->last()->getCode() ); |
||
313 | } |
||
314 | |||
315 | |||
316 | public function testSupplier() |
||
317 | { |
||
318 | $manager = \Aimeos\MShop::create( $this->context, 'supplier' ); |
||
319 | $supId = $manager->find( 'unitSupplier001' )->getId(); |
||
320 | |||
321 | $this->assertEquals( 2, count( $this->object->supplier( $supId )->search() ) ); |
||
322 | } |
||
323 | |||
324 | |||
325 | public function testText() |
||
328 | } |
||
329 | |||
330 | |||
331 | public function testTextCode() |
||
332 | { |
||
333 | $this->assertEquals( 1, count( $this->object->text( 'CNE' )->search() ) ); |
||
334 | } |
||
335 | |||
336 | |||
337 | public function testUses() |
||
338 | { |
||
339 | $this->assertSame( $this->object, $this->object->uses( ['text'] ) ); |
||
340 | } |
||
341 | } |
||
342 |