10
10
class FileSizeTest extends TestCase
11
11
{
12
12
/**
13
- * @test numeric string input.
13
+ * @test
14
14
*/
15
- public function bytes ()
15
+ public function base_two_conversions_are_accurate ()
16
+ {
17
+ $ size = new FileSize (10921134 , 2 );
18
+
19
+ $ this ->assertSame ($ size ->asAuto (), '10.42 MB ' );
20
+ }
21
+
22
+ /**
23
+ * @test
24
+ */
25
+ public function base_ten_conversions_are_accurate ()
26
+ {
27
+ $ size = new FileSize (10921134 , 10 );
28
+
29
+ $ this ->assertSame ($ size ->asAuto (), '10.92 MB ' );
30
+ }
31
+
32
+ /**
33
+ * @test
34
+ */
35
+ public function bytes_are_returned_as_an_integer ()
16
36
{
17
37
$ size = new FileSize ('128974848 ' );
18
38
19
39
$ this ->assertSame ($ size ->as ('B ' ), 128974848 );
20
40
}
21
41
22
42
/**
23
- * @test "partial bytes" are rounded up.
43
+ * @test
24
44
*/
25
- public function bytesRounding ()
45
+ public function partial_bytes_are_rounded_up ()
26
46
{
27
47
$ size = new FileSize ('99.7 bytes ' );
28
48
29
49
$ this ->assertSame ($ size ->as ('B ' ), 100 );
30
50
}
31
51
32
52
/**
33
- * @test #add.
53
+ * @test
34
54
*/
35
- public function add ()
55
+ public function sizes_can_be_added ()
36
56
{
37
57
$ size = new FileSize ('123 megabytes ' );
38
58
$ size ->add ('150 KiB ' );
@@ -41,64 +61,64 @@ public function add()
41
61
}
42
62
43
63
/**
44
- * @test #add with a negative value.
64
+ * @test
45
65
*/
46
- public function addNegative ()
66
+ public function negative_sizes_can_be_added ()
47
67
{
48
- $ size = new FileSize ('10MB ' );
49
- $ size ->add ('-20MB ' );
68
+ $ size = new FileSize ('10 MB ' );
69
+ $ size ->add ('-20 MB ' );
50
70
51
71
$ this ->assertSame ($ size ->asAuto (), '-10 MB ' );
52
72
}
53
73
54
74
/**
55
- * @test #subtract.
75
+ * @test
56
76
*/
57
- public function subtract ()
77
+ public function sizes_can_be_subtracted ()
58
78
{
59
- $ size = new FileSize ('123M ' );
79
+ $ size = new FileSize ('123 M ' );
60
80
$ size ->subtract ('150 kilobytes ' );
61
81
62
82
$ this ->assertSame ($ size ->as ('B ' ), 128821248 );
63
83
}
64
84
65
85
/**
66
- * @test #subtract with a negative value.
86
+ * @test
67
87
*/
68
- public function subtractNegative ()
88
+ public function negative_sizes_can_be_subtracted ()
69
89
{
70
- $ size = new FileSize ('10MB ' );
71
- $ size ->subtract ('-20MB ' );
90
+ $ size = new FileSize ('10 MB ' );
91
+ $ size ->subtract ('-20 MB ' );
72
92
73
93
$ this ->assertSame ($ size ->asAuto (), '30 MB ' );
74
94
}
75
95
76
96
/**
77
- * @test adding an array of items.
97
+ * @test
78
98
*/
79
- public function addMany ()
99
+ public function arrays_can_be_added ()
80
100
{
81
101
$ size = new FileSize ();
82
102
$ size ->add (['50mb ' , '140mb ' , '1.2mb ' ]);
83
103
84
- $ this ->assertSame ($ size ->as ('MB ' ), ( float ) 191.2 );
104
+ $ this ->assertSame ($ size ->as ('MB ' ), 191.2 );
85
105
}
86
106
87
107
/**
88
- * @test #multiplyBy.
108
+ * @test
89
109
*/
90
- public function multiplyBy ()
110
+ public function sizes_can_be_multiplied ()
91
111
{
92
112
$ size = new FileSize ('425.51 m ' );
93
113
$ size ->multiplyBy (9.125 );
94
114
95
- $ this ->assertSame ($ size ->as ('GB ' ), ( float ) 3.79 );
115
+ $ this ->assertSame ($ size ->as ('GB ' ), 3.79 );
96
116
}
97
117
98
118
/**
99
- * @test #divideBy.
119
+ * @test
100
120
*/
101
- public function divideBy ()
121
+ public function sizes_can_be_divided ()
102
122
{
103
123
$ size = new FileSize ('300K ' );
104
124
$ size ->divideBy (2 );
@@ -107,39 +127,39 @@ public function divideBy()
107
127
}
108
128
109
129
/**
110
- * @test upward unit conversion.
130
+ * @test
111
131
*/
112
- public function convertUp ()
132
+ public function sizes_can_be_converted_up ()
113
133
{
114
134
$ size = new FileSize ('123456789 TB ' );
115
135
116
136
$ this ->assertSame ($ size ->as ('exabytes ' ), 5.74 );
117
137
}
118
138
119
139
/**
120
- * @test downward unit conversion.
140
+ * @test
121
141
*/
122
- public function convertDown ()
142
+ public function sizes_can_be_converted_down ()
123
143
{
124
- $ size = new FileSize ('1 Gigabyte ' );
144
+ $ size = new FileSize ('1 GB ' );
125
145
126
- $ this ->assertSame ($ size ->as ('B ' ), 1073741824 );
146
+ $ this ->assertSame ($ size ->as ('megabytes ' ), ( float ) 1024 );
127
147
}
128
148
129
149
/**
130
- * @test when the unit has not changed.
150
+ * @test
131
151
*/
132
- public function noConvert ()
152
+ public function size_value_is_unchanged_without_conversion ()
133
153
{
134
- $ size = new FileSize ('525 Gibibytes ' );
154
+ $ size = new FileSize ('525 GB ' );
135
155
136
156
$ this ->assertSame ($ size ->as ('GB ' ), (float ) 525 );
137
157
}
138
158
139
159
/**
140
- * @test auto-formatting for a small value.
160
+ * @test
141
161
*/
142
- public function autoSmall ()
162
+ public function friendly_formatting_is_valid_for_small_values ()
143
163
{
144
164
$ size = new FileSize ('1.2345 KB ' );
145
165
$ size ->divideBy (3 );
@@ -148,52 +168,52 @@ public function autoSmall()
148
168
}
149
169
150
170
/**
151
- * @test auto-formatting for a large value.
171
+ * @test
152
172
*/
153
- public function autoLarge ()
173
+ public function friendly_formatting_is_valid_for_large_values ()
154
174
{
155
175
$ size = new FileSize ('1234522678.12 KB ' );
156
176
157
177
$ this ->assertSame ($ size ->asAuto (), '1.15 TB ' );
158
178
}
159
179
160
180
/**
161
- * @test the rounding in auto-formatting (should not leave trailing zeros).
181
+ * @test
162
182
*/
163
- public function autoRounding ()
183
+ public function custom_decimal_mark_is_supported ()
164
184
{
165
- $ size = new FileSize (' 158.1983 mb ' );
185
+ $ size = new FileSize (10921134 , 10 , ' , ' );
166
186
167
- $ this ->assertSame ($ size ->asAuto (), '158.2 MB ' );
187
+ $ this ->assertSame ($ size ->asAuto (), '10,92 MB ' );
168
188
}
169
189
170
190
/**
171
- * @test a decimal base conversion.
191
+ * @test
172
192
*/
173
- public function decimalBase ()
193
+ public function custom_decimal_and_thousands_marks_are_supported ()
174
194
{
175
- $ size = new FileSize (10921134 , 10 );
195
+ $ size = new FileSize (' 1.234.522.678,12 KB ' , 2 , ' , ' );
176
196
177
- $ this ->assertSame ($ size ->asAuto (), '10.92 MB ' );
197
+ $ this ->assertSame ($ size ->asAuto (), '1,15 TB ' );
178
198
}
179
199
180
200
/**
181
- * @test a custom decimal separator.
201
+ * @test
182
202
*/
183
- public function decimalMark ()
203
+ public function smallest_integer_is_supported ()
184
204
{
185
- $ size = new FileSize (10921134 , 10 , ' , ' );
205
+ $ size = new FileSize (PHP_INT_MIN );
186
206
187
- $ this ->assertSame ($ size ->asAuto (), ' 10,92 MB ' );
207
+ $ this ->assertIsNumeric ($ size ->as ( ' YB ' ) );
188
208
}
189
209
190
210
/**
191
- * @test custom decimal separators and thousands marks.
211
+ * @test
192
212
*/
193
- public function decimalAndThousandsMarks ()
213
+ public function largest_integer_is_supported ()
194
214
{
195
- $ size = new FileSize (' 1.234.522.678,12 KB ' , 2 , ' , ' );
215
+ $ size = new FileSize (PHP_INT_MAX );
196
216
197
- $ this ->assertSame ($ size ->asAuto (), ' 1,15 TB ' );
217
+ $ this ->assertIsNumeric ($ size ->as ( ' YB ' ) );
198
218
}
199
219
}
0 commit comments