@@ -33,87 +33,88 @@ class NumberTest extends TestCase
33
33
/**
34
34
* @dataProvider provideFromString_success
35
35
*/
36
- public function testFromString_success ($ number , $ expected )
36
+ public function testFromString_success ($ number , $ expected, $ purpose )
37
37
{
38
38
$ this ->assertEquals ($ expected , Number::fromString ($ number ));
39
39
}
40
40
41
41
public function provideFromString_success ()
42
42
{
43
43
return [
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 )],
44
+ ["410321-9202 " , new Number ('410321920 ' , 2 ), "String " ],
45
+ [4103219202 , new Number ('410321920 ' , 2 ), "Integer " ],
46
+ ['89148000003974165685 ' , new Number ('8914800000397416568 ' , 5 ), "Large number " ],
47
+ ['abc123 ' , new Number ('12 ' , 3 ), "Character in string " ],
48
+ [((string ) PHP_INT_MAX ).'21 ' , new Number (((string ) PHP_INT_MAX ).'2 ' , 1 ), "Larger than INT_MAX " ],
50
49
];
51
50
}
52
51
53
52
/**
54
53
* @dataProvider provideFromString_fail
55
54
*/
56
- public function testFromString_fail ($ number , $ expected )
55
+ public function testFromString_fail ($ number , $ expected, $ purpose )
57
56
{
58
- $ this ->expectException ($ expected );
57
+ $ this ->expectException ($ expected, $ purpose );
59
58
Number::fromString ($ number );
60
59
}
61
60
62
61
public function provideFromString_fail ()
63
62
{
64
63
return [
65
- ['' , \InvalidArgumentException::class],
66
- ['xyz ' , \InvalidArgumentException::class],
64
+ ['' , \InvalidArgumentException::class, "Empty string " ],
65
+ ['xyz ' , \InvalidArgumentException::class, "Invalid string " ],
66
+ [nullm \InvalidArgumentException::class, "Null " ],
67
67
];
68
68
}
69
69
70
70
/**
71
71
* @dataProvider provideToString_success
72
72
*/
73
- public function testToString_success ($ number , $ expected )
73
+ public function testToString_success ($ number , $ expected, $ purpose )
74
74
{
75
- $ this ->assertEquals ($ expected , (string ) $ number );
75
+ $ this ->assertEquals ($ expected , (string ) $ number, $ purpose );
76
76
}
77
77
78
78
public function provideToString_success ()
79
79
{
80
80
return [
81
- [new Number (12345 , 5 ), "123455 " ]
81
+ [new Number (12345 , 5 ), "123455 " , " Valid number " ]
82
82
];
83
83
}
84
84
85
85
/**
86
86
* @dataProvider provideNew_fail
87
87
*/
88
- public function testNew_fail ($ number , $ checkDigit , $ expected )
88
+ public function testNew_fail ($ number , $ checkDigit , $ expected, $ purpose )
89
89
{
90
- $ this ->expectException ($ expected );
90
+ $ this ->expectException ($ expected, $ purpose );
91
91
new Number ($ number , $ checkDigit );
92
92
}
93
93
94
94
public function provideNew_fail ()
95
95
{
96
96
return [
97
- ['abc123 ' , 1 , \InvalidArgumentException::class],
98
- ['123 ' , null , \InvalidArgumentException::class],
97
+ ['abc123 ' , 1 , \InvalidArgumentException::class, "Invalid number " ],
98
+ ['123 ' , null , \InvalidArgumentException::class, "Whitespace " ],
99
+ [null , null , \InvalidArgumentException::class, "Null " ],
99
100
];
100
101
}
101
102
102
103
/**
103
104
* @dataProvider provideProperties
104
105
*/
105
- public function testProperties ($ input , $ checkDigit )
106
+ public function testProperties ($ input , $ checkDigit, $ purpose )
106
107
{
107
108
$ number = new Number ($ input , $ checkDigit );
108
- $ this ->assertEquals ($ input , $ number ->getNumber ());
109
- $ this ->assertEquals ($ checkDigit , $ number ->getCheckDigit ());
109
+ $ this ->assertEquals ($ input , $ number ->getNumber (), $ purpose );
110
+ $ this ->assertEquals ($ checkDigit , $ number ->getCheckDigit (), $ purpose );
110
111
}
111
112
112
113
public function provideProperties ()
113
114
{
114
115
return [
115
- [123 , 1 ],
116
- [123 , null ],
116
+ [123 , 1 , " Valid number and checkdigit " ],
117
+ [123 , null , " Valid number and checkdigit (null) " ],
117
118
];
118
119
}
119
120
}
0 commit comments