1 | <?php |
||
16 | class DecimalValueTest extends DataValueTest { |
||
17 | |||
18 | /** |
||
19 | * @see DataValueTest::getClass |
||
20 | * |
||
21 | * @return string |
||
22 | */ |
||
23 | public function getClass() { |
||
26 | |||
27 | public function validConstructorArgumentsProvider() { |
||
28 | $argLists = array(); |
||
29 | |||
30 | $argLists[] = array( 42 ); |
||
31 | $argLists[] = array( -42 ); |
||
32 | $argLists[] = array( '-42' ); |
||
33 | $argLists[] = array( 4.2 ); |
||
34 | $argLists[] = array( -4.2 ); |
||
35 | $argLists[] = array( '+4.2' ); |
||
36 | $argLists[] = array( 0 ); |
||
37 | $argLists[] = array( 0.2 ); |
||
38 | $argLists[] = array( '-0.42' ); |
||
39 | $argLists[] = array( '-0.0' ); |
||
40 | $argLists[] = array( '-0' ); |
||
41 | $argLists[] = array( '+0' ); |
||
42 | $argLists[] = array( '+0.0' ); |
||
43 | $argLists[] = array( '+0.000' ); |
||
44 | $argLists[] = array( '+1.0' . str_repeat( ' ', 124 ) ); |
||
45 | |||
46 | return $argLists; |
||
47 | } |
||
48 | |||
49 | public function invalidConstructorArgumentsProvider() { |
||
50 | $argLists = array(); |
||
51 | |||
52 | $argLists[] = array( 'foo' ); |
||
53 | $argLists[] = array( '' ); |
||
54 | $argLists[] = array( '4.2' ); |
||
55 | $argLists[] = array( '++4.2' ); |
||
56 | $argLists[] = array( '--4.2' ); |
||
57 | $argLists[] = array( '-+4.2' ); |
||
58 | $argLists[] = array( '+-4.2' ); |
||
59 | $argLists[] = array( '-.42' ); |
||
60 | $argLists[] = array( '+.42' ); |
||
61 | $argLists[] = array( '.42' ); |
||
62 | $argLists[] = array( '.0' ); |
||
63 | $argLists[] = array( '-00' ); |
||
64 | $argLists[] = array( '+01.2' ); |
||
65 | $argLists[] = array( 'x2' ); |
||
66 | $argLists[] = array( '2x' ); |
||
67 | $argLists[] = array( '+0100' ); |
||
68 | $argLists[] = array( false ); |
||
69 | $argLists[] = array( true ); |
||
70 | $argLists[] = array( null ); |
||
71 | $argLists[] = array( '0x20' ); |
||
72 | $argLists[] = array( '+1.' . str_repeat( '0', 125 ) ); |
||
73 | |||
74 | return $argLists; |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * @see https://phabricator.wikimedia.org/T110728 |
||
79 | * @see http://www.regular-expressions.info/anchors.html#realend |
||
80 | */ |
||
81 | public function testTrailingNewlineRobustness() { |
||
82 | $value = DecimalValue::newFromArray( "-0.0\n" ); |
||
83 | |||
84 | $this->assertTrue( $value->isZero() ); |
||
85 | $this->assertSame( 'C:23:"DataValues\DecimalValue":11:{s:4:"+0.0";}', serialize( $value ) ); |
||
86 | $this->assertSame( '+0.0', $value->getValue(), 'getValue' ); |
||
87 | $this->assertSame( '+0.0', $value->getArrayValue(), 'getArrayValue' ); |
||
88 | $this->assertSame( '+0.0', $value->__toString(), '__toString' ); |
||
89 | $this->assertSame( '0', $value->getFractionalPart(), 'getFractionalPart' ); |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * @dataProvider compareProvider |
||
94 | */ |
||
95 | public function testCompare( DecimalValue $a, DecimalValue $b, $expected ) { |
||
102 | |||
103 | public function compareProvider() { |
||
130 | |||
131 | /** |
||
132 | * @dataProvider getSignProvider |
||
133 | */ |
||
134 | public function testGetSign( DecimalValue $value, $expected ) { |
||
138 | |||
139 | public function getSignProvider() { |
||
150 | |||
151 | /** |
||
152 | * @dataProvider getValueProvider |
||
153 | */ |
||
154 | public function testGetValue( DecimalValue $value, $expected ) { |
||
158 | |||
159 | public function getValueProvider() { |
||
181 | |||
182 | /** |
||
183 | * @dataProvider getValueFloatProvider |
||
184 | */ |
||
185 | public function testGetValueFloat( DecimalValue $value, $expected ) { |
||
189 | |||
190 | public function getValueFloatProvider() { |
||
209 | |||
210 | /** |
||
211 | * @dataProvider getGetIntegerPartProvider |
||
212 | */ |
||
213 | public function testGetIntegerPart( DecimalValue $value, $expected ) { |
||
217 | |||
218 | public function getGetIntegerPartProvider() { |
||
229 | |||
230 | /** |
||
231 | * @dataProvider getGetIntegerPartProvider |
||
232 | */ |
||
233 | public function testGetFractionalPart( DecimalValue $value, $expected ) { |
||
237 | |||
238 | public function getGetFractionalPartProvider() { |
||
248 | |||
249 | /** |
||
250 | * @dataProvider computeComplementProvider |
||
251 | */ |
||
252 | public function testComputeComplement( DecimalValue $value, $expected ) { |
||
259 | |||
260 | public function computeComplementProvider() { |
||
269 | |||
270 | /** |
||
271 | * @dataProvider computeComputeAbsolute |
||
272 | */ |
||
273 | public function testComputeAbsolute( DecimalValue $value, $expected ) { |
||
280 | |||
281 | public function computeComputeAbsolute() { |
||
292 | |||
293 | /** |
||
294 | * @dataProvider isZeroProvider |
||
295 | */ |
||
296 | public function testIsZero( DecimalValue $value, $expected ) { |
||
300 | |||
301 | public function isZeroProvider() { |
||
311 | |||
312 | } |
||
313 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: