Total Complexity | 73 |
Total Lines | 666 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like MathTrigTest 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 MathTrigTest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
14 | class MathTrigTest extends TestCase |
||
15 | { |
||
16 | public function setUp() |
||
17 | { |
||
18 | Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); |
||
19 | } |
||
20 | |||
21 | /** |
||
22 | * @dataProvider providerATAN2 |
||
23 | * |
||
24 | * @param mixed $expectedResult |
||
25 | */ |
||
26 | public function testATAN2($expectedResult, ...$args) |
||
27 | { |
||
28 | $result = MathTrig::ATAN2(...$args); |
||
1 ignored issue
–
show
|
|||
29 | self::assertEquals($expectedResult, $result, null, 1E-12); |
||
30 | } |
||
31 | |||
32 | public function providerATAN2() |
||
33 | { |
||
34 | return require 'data/Calculation/MathTrig/ATAN2.php'; |
||
35 | } |
||
36 | |||
37 | /** |
||
38 | * @dataProvider providerCEILING |
||
39 | * |
||
40 | * @param mixed $expectedResult |
||
41 | */ |
||
42 | public function testCEILING($expectedResult, ...$args) |
||
43 | { |
||
44 | $result = MathTrig::CEILING(...$args); |
||
1 ignored issue
–
show
|
|||
45 | self::assertEquals($expectedResult, $result, null, 1E-12); |
||
46 | } |
||
47 | |||
48 | public function providerCEILING() |
||
49 | { |
||
50 | return require 'data/Calculation/MathTrig/CEILING.php'; |
||
51 | } |
||
52 | |||
53 | /** |
||
54 | * @dataProvider providerCOMBIN |
||
55 | * |
||
56 | * @param mixed $expectedResult |
||
57 | */ |
||
58 | public function testCOMBIN($expectedResult, ...$args) |
||
59 | { |
||
60 | $result = MathTrig::COMBIN(...$args); |
||
61 | self::assertEquals($expectedResult, $result, null, 1E-12); |
||
62 | } |
||
63 | |||
64 | public function providerCOMBIN() |
||
65 | { |
||
66 | return require 'data/Calculation/MathTrig/COMBIN.php'; |
||
67 | } |
||
68 | |||
69 | /** |
||
70 | * @dataProvider providerEVEN |
||
71 | * |
||
72 | * @param mixed $expectedResult |
||
73 | */ |
||
74 | public function testEVEN($expectedResult, ...$args) |
||
75 | { |
||
76 | $result = MathTrig::EVEN(...$args); |
||
1 ignored issue
–
show
|
|||
77 | self::assertEquals($expectedResult, $result, null, 1E-12); |
||
78 | } |
||
79 | |||
80 | public function providerEVEN() |
||
81 | { |
||
82 | return require 'data/Calculation/MathTrig/EVEN.php'; |
||
83 | } |
||
84 | |||
85 | /** |
||
86 | * @dataProvider providerODD |
||
87 | * |
||
88 | * @param mixed $expectedResult |
||
89 | */ |
||
90 | public function testODD($expectedResult, ...$args) |
||
91 | { |
||
92 | $result = MathTrig::ODD(...$args); |
||
1 ignored issue
–
show
|
|||
93 | self::assertEquals($expectedResult, $result, null, 1E-12); |
||
94 | } |
||
95 | |||
96 | public function providerODD() |
||
97 | { |
||
98 | return require 'data/Calculation/MathTrig/ODD.php'; |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * @dataProvider providerFACT |
||
103 | * |
||
104 | * @param mixed $expectedResult |
||
105 | */ |
||
106 | public function testFACT($expectedResult, ...$args) |
||
107 | { |
||
108 | $result = MathTrig::FACT(...$args); |
||
1 ignored issue
–
show
|
|||
109 | self::assertEquals($expectedResult, $result, null, 1E-12); |
||
110 | } |
||
111 | |||
112 | public function providerFACT() |
||
113 | { |
||
114 | return require 'data/Calculation/MathTrig/FACT.php'; |
||
115 | } |
||
116 | |||
117 | /** |
||
118 | * @dataProvider providerFACTDOUBLE |
||
119 | * |
||
120 | * @param mixed $expectedResult |
||
121 | */ |
||
122 | public function testFACTDOUBLE($expectedResult, ...$args) |
||
123 | { |
||
124 | $result = MathTrig::FACTDOUBLE(...$args); |
||
1 ignored issue
–
show
|
|||
125 | self::assertEquals($expectedResult, $result, null, 1E-12); |
||
126 | } |
||
127 | |||
128 | public function providerFACTDOUBLE() |
||
129 | { |
||
130 | return require 'data/Calculation/MathTrig/FACTDOUBLE.php'; |
||
131 | } |
||
132 | |||
133 | /** |
||
134 | * @dataProvider providerFLOOR |
||
135 | * |
||
136 | * @param mixed $expectedResult |
||
137 | */ |
||
138 | public function testFLOOR($expectedResult, ...$args) |
||
139 | { |
||
140 | $result = MathTrig::FLOOR(...$args); |
||
1 ignored issue
–
show
|
|||
141 | self::assertEquals($expectedResult, $result, null, 1E-12); |
||
142 | } |
||
143 | |||
144 | public function providerFLOOR() |
||
145 | { |
||
146 | return require 'data/Calculation/MathTrig/FLOOR.php'; |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * @dataProvider providerGCD |
||
151 | * |
||
152 | * @param mixed $expectedResult |
||
153 | */ |
||
154 | public function testGCD($expectedResult, ...$args) |
||
155 | { |
||
156 | $result = MathTrig::GCD(...$args); |
||
157 | self::assertEquals($expectedResult, $result, null, 1E-12); |
||
158 | } |
||
159 | |||
160 | public function providerGCD() |
||
161 | { |
||
162 | return require 'data/Calculation/MathTrig/GCD.php'; |
||
163 | } |
||
164 | |||
165 | /** |
||
166 | * @dataProvider providerLCM |
||
167 | * |
||
168 | * @param mixed $expectedResult |
||
169 | */ |
||
170 | public function testLCM($expectedResult, ...$args) |
||
171 | { |
||
172 | $result = MathTrig::LCM(...$args); |
||
173 | self::assertEquals($expectedResult, $result, null, 1E-12); |
||
174 | } |
||
175 | |||
176 | public function providerLCM() |
||
177 | { |
||
178 | return require 'data/Calculation/MathTrig/LCM.php'; |
||
179 | } |
||
180 | |||
181 | /** |
||
182 | * @dataProvider providerINT |
||
183 | * |
||
184 | * @param mixed $expectedResult |
||
185 | */ |
||
186 | public function testINT($expectedResult, ...$args) |
||
187 | { |
||
188 | $result = MathTrig::INT(...$args); |
||
1 ignored issue
–
show
|
|||
189 | self::assertEquals($expectedResult, $result); |
||
190 | } |
||
191 | |||
192 | public function providerINT() |
||
195 | } |
||
196 | |||
197 | /** |
||
198 | * @dataProvider providerSIGN |
||
199 | * |
||
200 | * @param mixed $expectedResult |
||
201 | */ |
||
202 | public function testSIGN($expectedResult, ...$args) |
||
203 | { |
||
204 | $result = MathTrig::SIGN(...$args); |
||
1 ignored issue
–
show
|
|||
205 | self::assertEquals($expectedResult, $result, null, 1E-12); |
||
206 | } |
||
207 | |||
208 | public function providerSIGN() |
||
209 | { |
||
210 | return require 'data/Calculation/MathTrig/SIGN.php'; |
||
211 | } |
||
212 | |||
213 | /** |
||
214 | * @dataProvider providerPOWER |
||
215 | * |
||
216 | * @param mixed $expectedResult |
||
217 | */ |
||
218 | public function testPOWER($expectedResult, ...$args) |
||
219 | { |
||
220 | $result = MathTrig::POWER(...$args); |
||
1 ignored issue
–
show
|
|||
221 | self::assertEquals($expectedResult, $result, null, 1E-12); |
||
222 | } |
||
223 | |||
224 | public function providerPOWER() |
||
225 | { |
||
226 | return require 'data/Calculation/MathTrig/POWER.php'; |
||
227 | } |
||
228 | |||
229 | /** |
||
230 | * @dataProvider providerLOG |
||
231 | * |
||
232 | * @param mixed $expectedResult |
||
233 | */ |
||
234 | public function testLOG($expectedResult, ...$args) |
||
235 | { |
||
236 | $result = MathTrig::logBase(...$args); |
||
1 ignored issue
–
show
|
|||
237 | self::assertEquals($expectedResult, $result, null, 1E-12); |
||
238 | } |
||
239 | |||
240 | public function providerLOG() |
||
241 | { |
||
242 | return require 'data/Calculation/MathTrig/LOG.php'; |
||
243 | } |
||
244 | |||
245 | /** |
||
246 | * @dataProvider providerMOD |
||
247 | * |
||
248 | * @param mixed $expectedResult |
||
249 | */ |
||
250 | public function testMOD($expectedResult, ...$args) |
||
251 | { |
||
252 | $result = MathTrig::MOD(...$args); |
||
1 ignored issue
–
show
|
|||
253 | self::assertEquals($expectedResult, $result, null, 1E-12); |
||
254 | } |
||
255 | |||
256 | public function providerMOD() |
||
257 | { |
||
258 | return require 'data/Calculation/MathTrig/MOD.php'; |
||
259 | } |
||
260 | |||
261 | /** |
||
262 | * @dataProvider providerMDETERM |
||
263 | * |
||
264 | * @param mixed $expectedResult |
||
265 | */ |
||
266 | public function testMDETERM($expectedResult, ...$args) |
||
267 | { |
||
268 | $result = MathTrig::MDETERM(...$args); |
||
1 ignored issue
–
show
|
|||
269 | self::assertEquals($expectedResult, $result, null, 1E-12); |
||
270 | } |
||
271 | |||
272 | public function providerMDETERM() |
||
273 | { |
||
274 | return require 'data/Calculation/MathTrig/MDETERM.php'; |
||
275 | } |
||
276 | |||
277 | /** |
||
278 | * @dataProvider providerMINVERSE |
||
279 | * |
||
280 | * @param mixed $expectedResult |
||
281 | */ |
||
282 | public function testMINVERSE($expectedResult, ...$args) |
||
283 | { |
||
284 | $this->markTestIncomplete('TODO: This test should be fixed'); |
||
285 | |||
286 | $result = MathTrig::MINVERSE(...$args); |
||
287 | self::assertEquals($expectedResult, $result, null, 1E-12); |
||
288 | } |
||
289 | |||
290 | public function providerMINVERSE() |
||
291 | { |
||
292 | return require 'data/Calculation/MathTrig/MINVERSE.php'; |
||
293 | } |
||
294 | |||
295 | /** |
||
296 | * @dataProvider providerMMULT |
||
297 | * |
||
298 | * @param mixed $expectedResult |
||
299 | */ |
||
300 | public function testMMULT($expectedResult, ...$args) |
||
301 | { |
||
302 | $this->markTestIncomplete('TODO: This test should be fixed'); |
||
303 | |||
304 | $result = MathTrig::MMULT(...$args); |
||
305 | self::assertEquals($expectedResult, $result, null, 1E-12); |
||
306 | } |
||
307 | |||
308 | public function providerMMULT() |
||
309 | { |
||
310 | return require 'data/Calculation/MathTrig/MMULT.php'; |
||
311 | } |
||
312 | |||
313 | /** |
||
314 | * @dataProvider providerMULTINOMIAL |
||
315 | * |
||
316 | * @param mixed $expectedResult |
||
317 | */ |
||
318 | public function testMULTINOMIAL($expectedResult, ...$args) |
||
319 | { |
||
320 | $result = MathTrig::MULTINOMIAL(...$args); |
||
321 | self::assertEquals($expectedResult, $result, null, 1E-12); |
||
322 | } |
||
323 | |||
324 | public function providerMULTINOMIAL() |
||
325 | { |
||
326 | return require 'data/Calculation/MathTrig/MULTINOMIAL.php'; |
||
327 | } |
||
328 | |||
329 | /** |
||
330 | * @dataProvider providerMROUND |
||
331 | * |
||
332 | * @param mixed $expectedResult |
||
333 | */ |
||
334 | public function testMROUND($expectedResult, ...$args) |
||
335 | { |
||
336 | Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_VALUE); |
||
337 | $result = MathTrig::MROUND(...$args); |
||
338 | Calculation::setArrayReturnType(Calculation::RETURN_ARRAY_AS_ARRAY); |
||
339 | self::assertEquals($expectedResult, $result, null, 1E-12); |
||
340 | } |
||
341 | |||
342 | public function providerMROUND() |
||
343 | { |
||
344 | return require 'data/Calculation/MathTrig/MROUND.php'; |
||
345 | } |
||
346 | |||
347 | /** |
||
348 | * @dataProvider providerPRODUCT |
||
349 | * |
||
350 | * @param mixed $expectedResult |
||
351 | */ |
||
352 | public function testPRODUCT($expectedResult, ...$args) |
||
353 | { |
||
354 | $result = MathTrig::PRODUCT(...$args); |
||
355 | self::assertEquals($expectedResult, $result, null, 1E-12); |
||
356 | } |
||
357 | |||
358 | public function providerPRODUCT() |
||
359 | { |
||
360 | return require 'data/Calculation/MathTrig/PRODUCT.php'; |
||
361 | } |
||
362 | |||
363 | /** |
||
364 | * @dataProvider providerQUOTIENT |
||
365 | * |
||
366 | * @param mixed $expectedResult |
||
367 | */ |
||
368 | public function testQUOTIENT($expectedResult, ...$args) |
||
369 | { |
||
370 | $result = MathTrig::QUOTIENT(...$args); |
||
371 | self::assertEquals($expectedResult, $result, null, 1E-12); |
||
372 | } |
||
373 | |||
374 | public function providerQUOTIENT() |
||
377 | } |
||
378 | |||
379 | /** |
||
380 | * @dataProvider providerROUNDUP |
||
381 | * |
||
382 | * @param mixed $expectedResult |
||
383 | */ |
||
384 | public function testROUNDUP($expectedResult, ...$args) |
||
385 | { |
||
386 | $result = MathTrig::ROUNDUP(...$args); |
||
387 | self::assertEquals($expectedResult, $result, null, 1E-12); |
||
388 | } |
||
389 | |||
390 | public function providerROUNDUP() |
||
391 | { |
||
392 | return require 'data/Calculation/MathTrig/ROUNDUP.php'; |
||
393 | } |
||
394 | |||
395 | /** |
||
396 | * @dataProvider providerROUNDDOWN |
||
397 | * |
||
398 | * @param mixed $expectedResult |
||
399 | */ |
||
400 | public function testROUNDDOWN($expectedResult, ...$args) |
||
404 | } |
||
405 | |||
406 | public function providerROUNDDOWN() |
||
407 | { |
||
408 | return require 'data/Calculation/MathTrig/ROUNDDOWN.php'; |
||
409 | } |
||
410 | |||
411 | /** |
||
412 | * @dataProvider providerSERIESSUM |
||
413 | * |
||
414 | * @param mixed $expectedResult |
||
415 | */ |
||
416 | public function testSERIESSUM($expectedResult, ...$args) |
||
420 | } |
||
421 | |||
422 | public function providerSERIESSUM() |
||
423 | { |
||
424 | return require 'data/Calculation/MathTrig/SERIESSUM.php'; |
||
425 | } |
||
426 | |||
427 | /** |
||
428 | * @dataProvider providerSUMSQ |
||
429 | * |
||
430 | * @param mixed $expectedResult |
||
431 | */ |
||
432 | public function testSUMSQ($expectedResult, ...$args) |
||
433 | { |
||
434 | $result = MathTrig::SUMSQ(...$args); |
||
435 | self::assertEquals($expectedResult, $result, null, 1E-12); |
||
436 | } |
||
437 | |||
438 | public function providerSUMSQ() |
||
439 | { |
||
440 | return require 'data/Calculation/MathTrig/SUMSQ.php'; |
||
441 | } |
||
442 | |||
443 | /** |
||
444 | * @dataProvider providerTRUNC |
||
445 | * |
||
446 | * @param mixed $expectedResult |
||
447 | */ |
||
448 | public function testTRUNC($expectedResult, ...$args) |
||
449 | { |
||
450 | $result = MathTrig::TRUNC(...$args); |
||
1 ignored issue
–
show
|
|||
451 | self::assertEquals($expectedResult, $result, null, 1E-12); |
||
452 | } |
||
453 | |||
454 | public function providerTRUNC() |
||
457 | } |
||
458 | |||
459 | /** |
||
460 | * @dataProvider providerROMAN |
||
461 | * |
||
462 | * @param mixed $expectedResult |
||
463 | */ |
||
464 | public function testROMAN($expectedResult, ...$args) |
||
465 | { |
||
466 | $result = MathTrig::ROMAN(...$args); |
||
1 ignored issue
–
show
|
|||
467 | self::assertEquals($expectedResult, $result); |
||
468 | } |
||
469 | |||
470 | public function providerROMAN() |
||
471 | { |
||
472 | return require 'data/Calculation/MathTrig/ROMAN.php'; |
||
473 | } |
||
474 | |||
475 | /** |
||
476 | * @dataProvider providerSQRTPI |
||
477 | * |
||
478 | * @param mixed $expectedResult |
||
479 | */ |
||
480 | public function testSQRTPI($expectedResult, ...$args) |
||
481 | { |
||
482 | $result = MathTrig::SQRTPI(...$args); |
||
1 ignored issue
–
show
|
|||
483 | self::assertEquals($expectedResult, $result, null, 1E-12); |
||
484 | } |
||
485 | |||
486 | public function providerSQRTPI() |
||
489 | } |
||
490 | |||
491 | /** |
||
492 | * @dataProvider providerSUMIF |
||
493 | * |
||
494 | * @param mixed $expectedResult |
||
495 | */ |
||
496 | public function testSUMIF($expectedResult, ...$args) |
||
500 | } |
||
501 | |||
502 | public function providerSUMIF() |
||
503 | { |
||
504 | return require 'data/Calculation/MathTrig/SUMIF.php'; |
||
505 | } |
||
506 | |||
507 | /** |
||
508 | * @dataProvider providerSUBTOTAL |
||
509 | * |
||
510 | * @param mixed $expectedResult |
||
511 | */ |
||
512 | public function testSUBTOTAL($expectedResult, ...$args) |
||
513 | { |
||
514 | $cell = $this->getMockBuilder(Cell::class) |
||
515 | ->setMethods(['getValue']) |
||
516 | ->disableOriginalConstructor() |
||
517 | ->getMock(); |
||
518 | $cell->method('getValue') |
||
519 | ->willReturn(null); |
||
520 | $worksheet = $this->getMockBuilder(Worksheet::class) |
||
521 | ->setMethods(['cellExists', 'getCell']) |
||
522 | ->disableOriginalConstructor() |
||
523 | ->getMock(); |
||
524 | $worksheet->method('cellExists') |
||
525 | ->willReturn(true); |
||
526 | $worksheet->method('getCell') |
||
527 | ->willReturn($cell); |
||
528 | $cellReference = $this->getMockBuilder(Cell::class) |
||
529 | ->setMethods(['getWorksheet']) |
||
530 | ->disableOriginalConstructor() |
||
531 | ->getMock(); |
||
532 | $cellReference->method('getWorksheet') |
||
533 | ->willReturn($worksheet); |
||
534 | |||
535 | array_push($args, $cellReference); |
||
536 | $result = MathTrig::SUBTOTAL(...$args); |
||
537 | self::assertEquals($expectedResult, $result, null, 1E-12); |
||
538 | } |
||
539 | |||
540 | public function providerSUBTOTAL() |
||
543 | } |
||
544 | |||
545 | protected function rowVisibility() |
||
546 | { |
||
547 | $data = [1 => false, 2 => true, 3 => false, 4 => true, 5 => false, 6 => false, 7 => false, 8 => true, 9 => false, 10 => true, 11 => true]; |
||
548 | foreach ($data as $k => $v) { |
||
549 | yield $k => $v; |
||
550 | } |
||
551 | } |
||
552 | |||
553 | /** |
||
554 | * @dataProvider providerHiddenSUBTOTAL |
||
555 | * |
||
556 | * @param mixed $expectedResult |
||
557 | */ |
||
558 | public function testHiddenSUBTOTAL($expectedResult, ...$args) |
||
559 | { |
||
560 | $visibilityGenerator = $this->rowVisibility(); |
||
561 | |||
562 | $rowDimension = $this->getMockBuilder(RowDimension::class) |
||
563 | ->setMethods(['getVisible']) |
||
564 | ->disableOriginalConstructor() |
||
565 | ->getMock(); |
||
566 | $rowDimension->method('getVisible') |
||
567 | ->will($this->returnCallback(function () use ($visibilityGenerator) { |
||
568 | $result = $visibilityGenerator->current(); |
||
569 | $visibilityGenerator->next(); |
||
570 | |||
571 | return $result; |
||
572 | })); |
||
573 | $columnDimension = $this->getMockBuilder(ColumnDimension::class) |
||
574 | ->setMethods(['getVisible']) |
||
575 | ->disableOriginalConstructor() |
||
576 | ->getMock(); |
||
607 | } |
||
608 | |||
609 | public function providerHiddenSUBTOTAL() |
||
612 | } |
||
613 | |||
614 | protected function cellValues(array $cellValues) |
||
618 | } |
||
619 | } |
||
620 | |||
621 | protected function cellIsFormula(array $cellValues) |
||
622 | { |
||
623 | foreach ($cellValues as $cellValue) { |
||
624 | yield $cellValue[0] === '='; |
||
625 | } |
||
626 | } |
||
627 | |||
628 | /** |
||
629 | * @dataProvider providerNestedSUBTOTAL |
||
630 | * |
||
631 | * @param mixed $expectedResult |
||
632 | */ |
||
633 | public function testNestedSUBTOTAL($expectedResult, ...$args) |
||
634 | { |
||
635 | $cellValueGenerator = $this->cellValues(Functions::flattenArray(array_slice($args, 1))); |
||
636 | $cellIsFormulaGenerator = $this->cellIsFormula(Functions::flattenArray(array_slice($args, 1))); |
||
637 | |||
638 | $cell = $this->getMockBuilder(Cell::class) |
||
639 | ->setMethods(['getValue', 'isFormula']) |
||
640 | ->disableOriginalConstructor() |
||
641 | ->getMock(); |
||
642 | $cell->method('getValue') |
||
643 | ->will($this->returnCallback(function () use ($cellValueGenerator) { |
||
644 | $result = $cellValueGenerator->current(); |
||
645 | $cellValueGenerator->next(); |
||
646 | |||
647 | return $result; |
||
648 | })); |
||
649 | $cell->method('isFormula') |
||
650 | ->will($this->returnCallback(function () use ($cellIsFormulaGenerator) { |
||
651 | $result = $cellIsFormulaGenerator->current(); |
||
652 | $cellIsFormulaGenerator->next(); |
||
653 | |||
654 | return $result; |
||
655 | })); |
||
656 | $worksheet = $this->getMockBuilder(Worksheet::class) |
||
657 | ->setMethods(['cellExists', 'getCell']) |
||
658 | ->disableOriginalConstructor() |
||
659 | ->getMock(); |
||
660 | $worksheet->method('cellExists') |
||
661 | ->willReturn(true); |
||
662 | $worksheet->method('getCell') |
||
663 | ->willReturn($cell); |
||
664 | $cellReference = $this->getMockBuilder(Cell::class) |
||
665 | ->setMethods(['getWorksheet']) |
||
666 | ->disableOriginalConstructor() |
||
667 | ->getMock(); |
||
668 | $cellReference->method('getWorksheet') |
||
669 | ->willReturn($worksheet); |
||
670 | |||
671 | array_push($args, $cellReference); |
||
672 | |||
673 | $result = MathTrig::SUBTOTAL(...$args); |
||
674 | self::assertEquals($expectedResult, $result, null, 1E-12); |
||
675 | } |
||
676 | |||
677 | public function providerNestedSUBTOTAL() |
||
680 | } |
||
681 | } |
||
682 |