Total Complexity | 40 |
Total Lines | 315 |
Duplicated Lines | 0 % |
Changes | 0 |
Complex classes like FunctionsTest 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 FunctionsTest, and based on these observations, apply Extract Interface, too.
1 | <?php |
||
10 | class FunctionsTest extends TestCase |
||
11 | { |
||
12 | public function setUp() |
||
13 | { |
||
14 | Functions::setCompatibilityMode(Functions::COMPATIBILITY_EXCEL); |
||
15 | } |
||
16 | |||
17 | public function testDUMMY() |
||
18 | { |
||
19 | $result = Functions::DUMMY(); |
||
20 | self::assertEquals('#Not Yet Implemented', $result); |
||
21 | } |
||
22 | |||
23 | public function testDIV0() |
||
24 | { |
||
25 | $result = Functions::DIV0(); |
||
26 | self::assertEquals('#DIV/0!', $result); |
||
27 | } |
||
28 | |||
29 | public function testNA() |
||
30 | { |
||
31 | $result = Functions::NA(); |
||
32 | self::assertEquals('#N/A', $result); |
||
33 | } |
||
34 | |||
35 | public function testNAN() |
||
36 | { |
||
37 | $result = Functions::NAN(); |
||
38 | self::assertEquals('#NUM!', $result); |
||
39 | } |
||
40 | |||
41 | public function testNAME() |
||
42 | { |
||
43 | $result = Functions::NAME(); |
||
44 | self::assertEquals('#NAME?', $result); |
||
45 | } |
||
46 | |||
47 | public function testREF() |
||
48 | { |
||
49 | $result = Functions::REF(); |
||
50 | self::assertEquals('#REF!', $result); |
||
51 | } |
||
52 | |||
53 | public function testNULL() |
||
54 | { |
||
55 | $result = Functions::null(); |
||
56 | self::assertEquals('#NULL!', $result); |
||
57 | } |
||
58 | |||
59 | public function testVALUE() |
||
60 | { |
||
61 | $result = Functions::VALUE(); |
||
62 | self::assertEquals('#VALUE!', $result); |
||
63 | } |
||
64 | |||
65 | /** |
||
66 | * @dataProvider providerIsBlank |
||
67 | * |
||
68 | * @param mixed $expectedResult |
||
69 | */ |
||
70 | public function testIsBlank($expectedResult, ...$args) |
||
71 | { |
||
72 | $result = Functions::isBlank(...$args); |
||
1 ignored issue
–
show
|
|||
73 | self::assertEquals($expectedResult, $result, null, 1E-8); |
||
74 | } |
||
75 | |||
76 | public function providerIsBlank() |
||
77 | { |
||
78 | return require 'data/Calculation/Functions/IS_BLANK.php'; |
||
79 | } |
||
80 | |||
81 | /** |
||
82 | * @dataProvider providerIsErr |
||
83 | * |
||
84 | * @param mixed $expectedResult |
||
85 | */ |
||
86 | public function testIsErr($expectedResult, ...$args) |
||
87 | { |
||
88 | $result = Functions::isErr(...$args); |
||
1 ignored issue
–
show
|
|||
89 | self::assertEquals($expectedResult, $result, null, 1E-8); |
||
90 | } |
||
91 | |||
92 | public function providerIsErr() |
||
93 | { |
||
94 | return require 'data/Calculation/Functions/IS_ERR.php'; |
||
95 | } |
||
96 | |||
97 | /** |
||
98 | * @dataProvider providerIsError |
||
99 | * |
||
100 | * @param mixed $expectedResult |
||
101 | */ |
||
102 | public function testIsError($expectedResult, ...$args) |
||
103 | { |
||
104 | $result = Functions::isError(...$args); |
||
1 ignored issue
–
show
|
|||
105 | self::assertEquals($expectedResult, $result, null, 1E-8); |
||
106 | } |
||
107 | |||
108 | public function providerIsError() |
||
109 | { |
||
110 | return require 'data/Calculation/Functions/IS_ERROR.php'; |
||
111 | } |
||
112 | |||
113 | /** |
||
114 | * @dataProvider providerErrorType |
||
115 | * |
||
116 | * @param mixed $expectedResult |
||
117 | */ |
||
118 | public function testErrorType($expectedResult, ...$args) |
||
119 | { |
||
120 | $result = Functions::errorType(...$args); |
||
1 ignored issue
–
show
|
|||
121 | self::assertEquals($expectedResult, $result, null, 1E-8); |
||
122 | } |
||
123 | |||
124 | public function providerErrorType() |
||
125 | { |
||
126 | return require 'data/Calculation/Functions/ERROR_TYPE.php'; |
||
127 | } |
||
128 | |||
129 | /** |
||
130 | * @dataProvider providerIsLogical |
||
131 | * |
||
132 | * @param mixed $expectedResult |
||
133 | */ |
||
134 | public function testIsLogical($expectedResult, ...$args) |
||
135 | { |
||
136 | $result = Functions::isLogical(...$args); |
||
1 ignored issue
–
show
|
|||
137 | self::assertEquals($expectedResult, $result, null, 1E-8); |
||
138 | } |
||
139 | |||
140 | public function providerIsLogical() |
||
141 | { |
||
142 | return require 'data/Calculation/Functions/IS_LOGICAL.php'; |
||
143 | } |
||
144 | |||
145 | /** |
||
146 | * @dataProvider providerIsNa |
||
147 | * |
||
148 | * @param mixed $expectedResult |
||
149 | */ |
||
150 | public function testIsNa($expectedResult, ...$args) |
||
151 | { |
||
152 | $result = Functions::isNa(...$args); |
||
1 ignored issue
–
show
|
|||
153 | self::assertEquals($expectedResult, $result, null, 1E-8); |
||
154 | } |
||
155 | |||
156 | public function providerIsNa() |
||
157 | { |
||
158 | return require 'data/Calculation/Functions/IS_NA.php'; |
||
159 | } |
||
160 | |||
161 | /** |
||
162 | * @dataProvider providerIsNumber |
||
163 | * |
||
164 | * @param mixed $expectedResult |
||
165 | */ |
||
166 | public function testIsNumber($expectedResult, ...$args) |
||
167 | { |
||
168 | $result = Functions::isNumber(...$args); |
||
1 ignored issue
–
show
|
|||
169 | self::assertEquals($expectedResult, $result, null, 1E-8); |
||
170 | } |
||
171 | |||
172 | public function providerIsNumber() |
||
173 | { |
||
174 | return require 'data/Calculation/Functions/IS_NUMBER.php'; |
||
175 | } |
||
176 | |||
177 | /** |
||
178 | * @dataProvider providerIsText |
||
179 | * |
||
180 | * @param mixed $expectedResult |
||
181 | */ |
||
182 | public function testIsText($expectedResult, ...$args) |
||
186 | } |
||
187 | |||
188 | public function providerIsText() |
||
189 | { |
||
190 | return require 'data/Calculation/Functions/IS_TEXT.php'; |
||
191 | } |
||
192 | |||
193 | /** |
||
194 | * @dataProvider providerIsNonText |
||
195 | * |
||
196 | * @param mixed $expectedResult |
||
197 | */ |
||
198 | public function testIsNonText($expectedResult, ...$args) |
||
199 | { |
||
200 | $result = Functions::isNonText(...$args); |
||
1 ignored issue
–
show
|
|||
201 | self::assertEquals($expectedResult, $result, null, 1E-8); |
||
202 | } |
||
203 | |||
204 | public function providerIsNonText() |
||
205 | { |
||
206 | return require 'data/Calculation/Functions/IS_NONTEXT.php'; |
||
207 | } |
||
208 | |||
209 | /** |
||
210 | * @dataProvider providerIsEven |
||
211 | * |
||
212 | * @param mixed $expectedResult |
||
213 | */ |
||
214 | public function testIsEven($expectedResult, ...$args) |
||
215 | { |
||
216 | $result = Functions::isEven(...$args); |
||
1 ignored issue
–
show
|
|||
217 | self::assertEquals($expectedResult, $result, null, 1E-8); |
||
218 | } |
||
219 | |||
220 | public function providerIsEven() |
||
223 | } |
||
224 | |||
225 | /** |
||
226 | * @dataProvider providerIsOdd |
||
227 | * |
||
228 | * @param mixed $expectedResult |
||
229 | */ |
||
230 | public function testIsOdd($expectedResult, ...$args) |
||
231 | { |
||
232 | $result = Functions::isOdd(...$args); |
||
1 ignored issue
–
show
|
|||
233 | self::assertEquals($expectedResult, $result, null, 1E-8); |
||
234 | } |
||
235 | |||
236 | public function providerIsOdd() |
||
237 | { |
||
238 | return require 'data/Calculation/Functions/IS_ODD.php'; |
||
239 | } |
||
240 | |||
241 | /** |
||
242 | * @dataProvider providerTYPE |
||
243 | * |
||
244 | * @param mixed $expectedResult |
||
245 | */ |
||
246 | public function testTYPE($expectedResult, ...$args) |
||
247 | { |
||
248 | $result = Functions::TYPE(...$args); |
||
1 ignored issue
–
show
|
|||
249 | self::assertEquals($expectedResult, $result, null, 1E-8); |
||
250 | } |
||
251 | |||
252 | public function providerTYPE() |
||
253 | { |
||
254 | return require 'data/Calculation/Functions/TYPE.php'; |
||
255 | } |
||
256 | |||
257 | /** |
||
258 | * @dataProvider providerN |
||
259 | * |
||
260 | * @param mixed $expectedResult |
||
261 | */ |
||
262 | public function testN($expectedResult, ...$args) |
||
266 | } |
||
267 | |||
268 | public function providerN() |
||
271 | } |
||
272 | |||
273 | /** |
||
274 | * @dataProvider providerIsFormula |
||
275 | * |
||
276 | * @param mixed $expectedResult |
||
277 | * @param mixed $value |
||
278 | */ |
||
279 | public function testIsFormula($expectedResult, $value = 'undefined') |
||
280 | { |
||
281 | $ourCell = null; |
||
282 | if ($value !== 'undefined') { |
||
283 | $remoteCell = $this->getMockBuilder(Cell::class) |
||
284 | ->disableOriginalConstructor() |
||
285 | ->getMock(); |
||
286 | $remoteCell->method('getValue') |
||
287 | ->will($this->returnValue($value)); |
||
288 | |||
289 | $sheet = $this->getMockBuilder(Worksheet::class) |
||
304 | } |
||
305 | |||
306 | public function providerIsFormula() |
||
309 | } |
||
310 | |||
311 | /** |
||
312 | * @dataProvider providerIfCondition |
||
313 | * |
||
314 | * @param mixed $expectedResult |
||
315 | */ |
||
316 | public function testIfCondition($expectedResult, ...$args) |
||
320 | } |
||
321 | |||
322 | public function providerIfCondition() |
||
327 |