3131class NumberTest extends TestCase
3232{
3333 /**
34- * @dataProvider provideWithCheckDigit_success
34+ * @dataProvider provideFromString_success
3535 */
36- public function testWithCheckDigit_success ($ number , $ expected )
36+ public function testFromString_success ($ number , $ expected )
3737 {
3838 $ this ->assertEquals ($ expected , Number::fromString ($ number ));
3939 }
4040
41- public function provideWithCheckDigit_success ()
41+ public function provideFromString_success ()
4242 {
4343 return [
44- ["410321-9202 " , new Number (410321920 , 2 )],
45- [4103219202 , new Number (410321920 , 2 )]
44+ ["410321-9202 " , new Number ('410321920 ' , 2 )],
45+ [4103219202 , new Number ('410321920 ' , 2 )],
46+ ['89148000003974165685 ' , new Number ('8914800000397416568 ' , 5 )],
47+ ['abc123 ' , new Number ('12 ' , 3 )],
48+ // Use any number that is larger then PHP_INT_MAX.
49+ [((string ) PHP_INT_MAX ).'21 ' , new Number (((string ) PHP_INT_MAX ).'2 ' , 1 )],
50+ ];
51+ }
52+
53+ /**
54+ * @dataProvider provideFromString_fail
55+ */
56+ public function testFromString_fail ($ number , $ checkDigit , $ expected )
57+ {
58+ $ this ->expectException ($ expected );
59+ new Number ($ number , $ checkDigit );
60+ }
61+
62+ public function provideFromString_fail ()
63+ {
64+ return [
65+ ['' , 1 , \InvalidArgumentException::class],
66+ ['xyz ' , null , \InvalidArgumentException::class],
4667 ];
4768 }
4869
@@ -60,4 +81,21 @@ public function provideToString_success()
6081 [new Number (12345 , 5 ), "123455 " ]
6182 ];
6283 }
84+
85+ /**
86+ * @dataProvider provideNew_fail
87+ */
88+ public function testNew_fail ($ number , $ checkDigit , $ expected )
89+ {
90+ $ this ->expectException ($ expected );
91+ new Number ($ number , $ checkDigit );
92+ }
93+
94+ public function provideNew_fail ()
95+ {
96+ return [
97+ ['abc123 ' , 1 , \InvalidArgumentException::class],
98+ ['123 ' , null , \InvalidArgumentException::class],
99+ ];
100+ }
63101}
0 commit comments