1
- <?php //declare(strict_types=1);
1
+ <?php
2
2
3
3
use bcmath_compat \BCMath ;
4
4
5
- use PHPUnit \Framework \Attributes \RequiresPhpExtension ;
6
- use PHPUnit \Framework \Attributes \RequiresPhp ;
7
- use PHPUnit \Framework \Attributes \DataProvider ;
8
- use PHPUnit \Framework \TestCase ;
9
- // use PHPUnit\Framework\Attributes\TestWith;
10
-
11
5
/**
12
- * requires extension bcmath
6
+ * @ requires extension bcmath
13
7
*/
14
- #[RequiresPhpExtension('bcmath ' )]
15
- class BCMathTest extends TestCase
8
+ class BCMathTest extends PHPUnit \Framework \TestCase
16
9
{
17
- static $ emsg = '' ;
18
10
/**
19
11
* Produces all combinations of test values.
20
12
*
21
13
* @return array
22
14
*/
23
- public static function generateTwoParams ()
15
+ public function generateTwoParams ()
24
16
{
25
17
$ r = [
26
18
['9 ' , '9 ' ],
@@ -53,7 +45,9 @@ public static function generateTwoParams()
53
45
return $ r ;
54
46
}
55
47
56
- #[DataProvider('generateTwoParams ' )]
48
+ /**
49
+ * @dataProvider generateTwoParams
50
+ */
57
51
public function testAdd (...$ params )
58
52
{
59
53
$ a = bcadd (...$ params );
@@ -66,7 +60,9 @@ public function testAdd(...$params)
66
60
$ this ->assertSame ($ a , $ b );
67
61
}
68
62
69
- #[DataProvider('generateTwoParams ' )]
63
+ /**
64
+ * @dataProvider generateTwoParams
65
+ */
70
66
public function testSub (...$ params )
71
67
{
72
68
$ a = bcsub (...$ params );
@@ -80,11 +76,9 @@ public function testSub(...$params)
80
76
}
81
77
82
78
/**
83
- * requires PHP 7.3
79
+ * @dataProvider generateTwoParams
80
+ * @requires PHP 7.3
84
81
*/
85
-
86
- #[RequiresPhp('>7.3 ' )]
87
- #[DataProvider('generateTwoParams ' )]
88
82
public function testMul (...$ params )
89
83
{
90
84
$ a = bcmul (...$ params );
@@ -97,7 +91,9 @@ public function testMul(...$params)
97
91
$ this ->assertSame ($ a , $ b );
98
92
}
99
93
100
- #[DataProvider('generateTwoParams ' )]
94
+ /**
95
+ * @dataProvider generateTwoParams
96
+ */
101
97
public function testDiv (...$ params )
102
98
{
103
99
if ($ params [1 ] === '0 ' || $ params [1 ] === '-0 ' ) {
@@ -114,12 +110,9 @@ public function testDiv(...$params)
114
110
}
115
111
116
112
/**
117
- * dataProvider generateTwoParams
118
- * requires PHP 7.2
113
+ * @ dataProvider generateTwoParams
114
+ * @ requires PHP 7.2
119
115
*/
120
-
121
- #[DataProvider('generateTwoParams ' )]
122
- #[RequiresPhp('>7.2 ' )]
123
116
public function testMod (...$ params )
124
117
{
125
118
if ($ params [1 ] === '0 ' || $ params [1 ] === '-0 ' ) {
@@ -140,7 +133,7 @@ public function testMod(...$params)
140
133
*
141
134
* @return array
142
135
*/
143
- public static function generatePowParams ()
136
+ public function generatePowParams ()
144
137
{
145
138
return [
146
139
['9 ' , '9 ' ],
@@ -161,10 +154,8 @@ public static function generatePowParams()
161
154
162
155
/**
163
156
* @dataProvider generatePowParams
164
- * requires PHP 7.3
157
+ * @ requires PHP 7.3
165
158
*/
166
- #[DataProvider('generatePowParams ' )]
167
- #[RequiresPhp('>7.3 ' )]
168
159
public function testPow (...$ params )
169
160
{
170
161
$ a = bcpow (...$ params );
@@ -177,7 +168,7 @@ public function testPow(...$params)
177
168
*
178
169
* @return array
179
170
*/
180
- public static function generatePowModParams ()
171
+ public function generatePowModParams ()
181
172
{
182
173
return [
183
174
['9 ' , '9 ' , '17 ' ],
@@ -197,13 +188,10 @@ public static function generatePowModParams()
197
188
}
198
189
199
190
/**
200
- * dataProvider generatePowModParams
201
- * requires PHP 7.3
191
+ * @ dataProvider generatePowModParams
192
+ * @ requires PHP 7.3
202
193
*/
203
- #[DataProvider('generatePowModParams ' )]
204
- #[RequiresPhp('>7.3 ' )]
205
-
206
- public function testPowMod (...$ params )
194
+ public function testPowMod (...$ params )
207
195
{
208
196
$ a = bcpowmod (...$ params );
209
197
$ b = BCMath::powmod (...$ params );
@@ -227,19 +215,9 @@ public function testSqrt()
227
215
228
216
public function testBoolScale ()
229
217
{
230
- if (false ) {
231
- $ exception_thrown = false ;
232
- try {
233
- $ a = bcadd ('5 ' , '2 ' , false );
234
- } catch (TypeError $ e ) {
235
- $ exception_thrown = true ;
236
- }
237
- $ this ->assertSame (true , $ exception_thrown );
238
- } else {
239
- $ a = bcadd ('5 ' ,'2 ' , false );
240
- $ b = BCMath::add ('5 ' , '2 ' , false );
241
- $ this ->assertSame ($ a , $ b );
242
- }
218
+ $ a = bcadd ('5 ' , '2 ' , false );
219
+ $ b = BCMath::add ('5 ' , '2 ' , false );
220
+ $ this ->assertSame ($ a , $ b );
243
221
}
244
222
245
223
public function testIntParam ()
@@ -268,75 +246,4 @@ public function setExpectedException($name, $message = null, $code = null)
268
246
$ this ->expectExceptionCode ($ code );
269
247
}
270
248
}
271
-
272
- public static function generateScaleCallstaticParams ()
273
- {
274
- return [
275
- [4 ],
276
- [4 ,2 ],
277
- [4 ,2 ,3 ],
278
- [4 ,2 ,3 ,5 ],
279
- ];
280
- }
281
-
282
- #[DataProvider('generateScaleCallstaticParams ' )]
283
- public function test_argumentsScaleCallstatic (...$ params )
284
- {
285
- //scale with 1, 2, 3 parameters
286
- if (func_num_args () == 1 ) {
287
- bcscale (...$ params );
288
- BCMath::scale (...$ params );
289
- $ scale = bcscale ();
290
- $ orig = $ params [0 ];
291
- $ this ->assertSame ($ orig ,$ scale );
292
- $ scale = BCMath::scale ();
293
- $ this ->assertSame ($ orig ,$ scale );
294
- } else {
295
- $ exception_thrown = false ;
296
- try {
297
- BCMath::scale (...$ params );
298
- } catch (ArgumentCountError $ e ) {
299
- $ exception_thrown = true ;
300
- }
301
- $ this ->assertSame (true , $ exception_thrown );
302
- if (true ) {
303
- // start the unit test with: (showing the wrong given values)
304
- // phpunit --testdox-test testdox.txt --display-skipped
305
- $ this ->markTestSkipped ('ArgumentCountError in ' . $ e ->getFile () . ': ' . $ e ->getLine () . ' : ' . $ e ->getMessage ());
306
- }
307
- }
308
- }
309
- public static function generatePowModCallstaticParams ()
310
- {
311
- return [
312
- ['9 ' ],
313
- ['9 ' , '17 ' ],
314
- ['9 ' , '17 ' , '-111 ' ],
315
- ['9 ' , '17 ' , '-111 ' , 5 ],
316
- ['9 ' , '17 ' , '-111 ' , 5 , 8 ],
317
- ];
318
- }
319
- #[DataProvider('generatePowModCallstaticParams ' )]
320
- public function test_argumentsPowModCallstatic (...$ params )
321
- {
322
- //scale with 1, 2, 3 parameters
323
- if (func_num_args () > 2 && func_num_args () < 5 ) {
324
- $ a = bcpowmod (...$ params );
325
- $ b = BCMath::powmod (...$ params );
326
- $ this ->assertSame ($ a ,$ b );
327
- } else {
328
- $ exception_thrown = false ;
329
- try {
330
- BCMath::powmod (...$ params );
331
- } catch (ArgumentCountError $ e ) {
332
- $ exception_thrown = true ;
333
- }
334
- $ this ->assertSame (true , $ exception_thrown );
335
- if (true ) {
336
- // start the unit test with: (showing the wrong given values)
337
- // phpunit --testdox-test testdox.txt --display-skipped
338
- $ this ->markTestSkipped ('ArgumentCountError in ' . $ e ->getFile () . ': ' . $ e ->getLine () . ' : ' . $ e ->getMessage ());
339
- }
340
- }
341
- }
342
249
}
0 commit comments