forked from cartalyst/stripe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AmountConverterTest.php
251 lines (228 loc) · 14.2 KB
/
AmountConverterTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
<?php
/**
* Part of the Stripe package.
*
* NOTICE OF LICENSE
*
* Licensed under the 3-clause BSD License.
*
* This source file is subject to the 3-clause BSD License that is
* bundled with this package in the LICENSE file.
*
* @package Stripe
* @version 2.0.4
* @author Cartalyst LLC
* @license BSD License (3-clause)
* @copyright (c) 2011-2016, Cartalyst LLC
* @link http://cartalyst.com
*/
namespace Cartalyst\Stripe\Tests;
use PHPUnit_Framework_TestCase;
use Cartalyst\Stripe\AmountConverter;
class AmountConverterTest extends PHPUnit_Framework_TestCase
{
/** @test */
public function it_can_convert_a_number_to_cents()
{
// Miscellaneous
$this->assertSame('0.00', AmountConverter::convert('a'));
$this->assertSame('1300', AmountConverter::convert('1a3f'));
$this->assertSame('030', AmountConverter::convert('a0f.30'));
$this->assertSame('1330', AmountConverter::convert('1a3f.30'));
// 1 cent (0 U.S. dollars) + (1 U.S. cents) (this is not allowed by Stripe though)
$this->assertSame('010', AmountConverter::convert(.10));
$this->assertSame('010', AmountConverter::convert(0.10));
$this->assertSame('010', AmountConverter::convert(0.10001));
$this->assertSame('010', AmountConverter::convert(0.10011));
$this->assertSame('010', AmountConverter::convert(0.10111));
$this->assertSame('010', AmountConverter::convert('0.10001'));
$this->assertSame('010', AmountConverter::convert('0.10011'));
$this->assertSame('010', AmountConverter::convert('0.10111'));
// 50 cents (0 U.S. dollars) + (50 U.S. cents)
$this->assertSame('050', AmountConverter::convert(.50));
$this->assertSame('050', AmountConverter::convert(0.50));
$this->assertSame('050', AmountConverter::convert(0.50001));
$this->assertSame('050', AmountConverter::convert(0.50011));
$this->assertSame('050', AmountConverter::convert(0.50111));
$this->assertSame('050', AmountConverter::convert('0.50001'));
$this->assertSame('050', AmountConverter::convert('0.50011'));
$this->assertSame('050', AmountConverter::convert('0.50111'));
// 54 cents (0 U.S. dollars) + (54 U.S. cents)
$this->assertSame('054', AmountConverter::convert(.54));
$this->assertSame('054', AmountConverter::convert(0.54));
$this->assertSame('054', AmountConverter::convert(0.54001));
$this->assertSame('054', AmountConverter::convert(0.54011));
$this->assertSame('054', AmountConverter::convert(0.54111));
$this->assertSame('054', AmountConverter::convert('0.54001'));
$this->assertSame('054', AmountConverter::convert('0.54011'));
$this->assertSame('054', AmountConverter::convert('0.54111'));
// 1 dollar (1 U.S. dollars) + (0 U.S. cents)
$this->assertSame('100', AmountConverter::convert(1));
$this->assertSame('100', AmountConverter::convert('1'));
$this->assertSame('100', AmountConverter::convert(1.0));
$this->assertSame('100', AmountConverter::convert(1.00));
$this->assertSame('100', AmountConverter::convert('1.00'));
$this->assertSame('100', AmountConverter::convert(1.00001));
$this->assertSame('100', AmountConverter::convert(1.00011));
$this->assertSame('100', AmountConverter::convert(1.00111));
$this->assertSame('100', AmountConverter::convert('1.00001'));
$this->assertSame('100', AmountConverter::convert('1.00011'));
$this->assertSame('100', AmountConverter::convert('1.00111'));
// 1.50 dollar (1 U.S. dollars) + (50 U.S. cents)
$this->assertSame('150', AmountConverter::convert(1.50));
$this->assertSame('150', AmountConverter::convert(1.50));
$this->assertSame('150', AmountConverter::convert('1.50'));
$this->assertSame('150', AmountConverter::convert(1.50001));
$this->assertSame('150', AmountConverter::convert('1.50001'));
// 1.53 dollar (1 U.S. dollars) + (53 U.S. cents)
$this->assertSame('153', AmountConverter::convert(1.53));
$this->assertSame('153', AmountConverter::convert(1.53));
$this->assertSame('153', AmountConverter::convert('1.53'));
$this->assertSame('153', AmountConverter::convert(1.53001));
$this->assertSame('153', AmountConverter::convert(1.53011));
$this->assertSame('153', AmountConverter::convert(1.53111));
$this->assertSame('153', AmountConverter::convert('1.53001'));
$this->assertSame('153', AmountConverter::convert('1.53011'));
$this->assertSame('153', AmountConverter::convert('1.53111'));
// 4 dollars (1 U.S. dollars) + (0 U.S. cents)
$this->assertSame('400', AmountConverter::convert(4));
$this->assertSame('400', AmountConverter::convert('4'));
$this->assertSame('400', AmountConverter::convert(4.0));
$this->assertSame('400', AmountConverter::convert(4.00));
$this->assertSame('400', AmountConverter::convert('4.00'));
$this->assertSame('400', AmountConverter::convert(4.00001));
$this->assertSame('400', AmountConverter::convert(4.00011));
$this->assertSame('400', AmountConverter::convert(4.00111));
$this->assertSame('400', AmountConverter::convert('4.00001'));
$this->assertSame('400', AmountConverter::convert('4.00011'));
$this->assertSame('400', AmountConverter::convert('4.00111'));
// 10 dollars (10 U.S. dollars) + (70 U.S. cents)
$this->assertSame('1000', AmountConverter::convert(10));
$this->assertSame('1000', AmountConverter::convert('10'));
$this->assertSame('1000', AmountConverter::convert(10.0));
$this->assertSame('1000', AmountConverter::convert(10.00));
$this->assertSame('1000', AmountConverter::convert('10.00'));
$this->assertSame('1000', AmountConverter::convert(10.00001));
$this->assertSame('1000', AmountConverter::convert(10.00011));
$this->assertSame('1000', AmountConverter::convert(10.00111));
$this->assertSame('1000', AmountConverter::convert('10.00001'));
$this->assertSame('1000', AmountConverter::convert('10.00011'));
$this->assertSame('1000', AmountConverter::convert('10.00111'));
// 12 dollars (12 U.S. dollars) + (0 U.S. cents)
$this->assertSame('1200', AmountConverter::convert(12));
$this->assertSame('1200', AmountConverter::convert('12'));
$this->assertSame('1200', AmountConverter::convert(12.0));
$this->assertSame('1200', AmountConverter::convert(12.00));
$this->assertSame('1200', AmountConverter::convert('12.00'));
$this->assertSame('1200', AmountConverter::convert(12.00001));
$this->assertSame('1200', AmountConverter::convert(12.00011));
$this->assertSame('1200', AmountConverter::convert(12.00111));
$this->assertSame('1200', AmountConverter::convert('12.00001'));
$this->assertSame('1200', AmountConverter::convert('12.00011'));
$this->assertSame('1200', AmountConverter::convert('12.00111'));
// 12.01 dollars (12 U.S. dollars) + (1 U.S. cents)
$this->assertSame('1201', AmountConverter::convert(12.01));
$this->assertSame('1201', AmountConverter::convert('12.01'));
$this->assertSame('1201', AmountConverter::convert('12.01'));
$this->assertSame('1201', AmountConverter::convert(12.01001));
$this->assertSame('1201', AmountConverter::convert(12.01001));
$this->assertSame('1201', AmountConverter::convert(12.01111));
$this->assertSame('1201', AmountConverter::convert('12.01001'));
$this->assertSame('1201', AmountConverter::convert('12.01011'));
$this->assertSame('1201', AmountConverter::convert('12.01111'));
// 12.17 dollars (12 U.S. dollars) + (17 U.S. cents)
$this->assertSame('1217', AmountConverter::convert(12.17));
$this->assertSame('1217', AmountConverter::convert('12.17'));
$this->assertSame('1217', AmountConverter::convert(12.17001));
$this->assertSame('1217', AmountConverter::convert(12.17011));
$this->assertSame('1217', AmountConverter::convert(12.17111));
$this->assertSame('1217', AmountConverter::convert('12.17001'));
$this->assertSame('1217', AmountConverter::convert('12.17011'));
$this->assertSame('1217', AmountConverter::convert('12.17111'));
// 12.70 dollars (12 U.S. dollars) + (70 U.S. cents)
$this->assertSame('1270', AmountConverter::convert(12.7));
$this->assertSame('1270', AmountConverter::convert(12.70));
$this->assertSame('1270', AmountConverter::convert('12.70'));
$this->assertSame('1270', AmountConverter::convert(12.70001));
$this->assertSame('1270', AmountConverter::convert(12.70011));
$this->assertSame('1270', AmountConverter::convert(12.70111));
$this->assertSame('1270', AmountConverter::convert('12.70001'));
$this->assertSame('1270', AmountConverter::convert('12.70011'));
$this->assertSame('1270', AmountConverter::convert('12.70111'));
// 12.90 dollars (12 U.S. dollars) + (90 U.S. cents)
$this->assertSame('1290', AmountConverter::convert(12.9));
$this->assertSame('1290', AmountConverter::convert(12.90));
$this->assertSame('1290', AmountConverter::convert('12.90'));
$this->assertSame('1290', AmountConverter::convert(12.90001));
$this->assertSame('1290', AmountConverter::convert(12.90011));
$this->assertSame('1290', AmountConverter::convert(12.90111));
$this->assertSame('1290', AmountConverter::convert('12.90001'));
$this->assertSame('1290', AmountConverter::convert('12.90011'));
$this->assertSame('1290', AmountConverter::convert('12.90111'));
// 12.99 dollars (12 U.S. dollars) + (99 U.S. cents)
$this->assertSame('1299', AmountConverter::convert(12.99));
$this->assertSame('1299', AmountConverter::convert('12.99'));
$this->assertSame('1299', AmountConverter::convert(12.99001));
$this->assertSame('1299', AmountConverter::convert(12.99011));
$this->assertSame('1299', AmountConverter::convert(12.99111));
$this->assertSame('1299', AmountConverter::convert('12.99001'));
$this->assertSame('1299', AmountConverter::convert('12.99011'));
$this->assertSame('1299', AmountConverter::convert('12.99111'));
// 12.993 dollars (1 U.S. dollars) + (99 U.S. cents)
$this->assertSame('1299', AmountConverter::convert(12.993));
$this->assertSame('1299', AmountConverter::convert('12.993'));
$this->assertSame('1299', AmountConverter::convert(12.99301));
$this->assertSame('1299', AmountConverter::convert(12.99311));
$this->assertSame('1299', AmountConverter::convert('12.99301'));
$this->assertSame('1299', AmountConverter::convert('12.99311'));
// 50 dollars (50 U.S. dollars) + (0 U.S. cents)
$this->assertSame('5000', AmountConverter::convert(50));
$this->assertSame('5000', AmountConverter::convert('50'));
$this->assertSame('5000', AmountConverter::convert(50.0));
$this->assertSame('5000', AmountConverter::convert(50.00));
$this->assertSame('5000', AmountConverter::convert('50.00'));
$this->assertSame('5000', AmountConverter::convert(50.00001));
$this->assertSame('5000', AmountConverter::convert(50.00011));
$this->assertSame('5000', AmountConverter::convert(50.00111));
$this->assertSame('5000', AmountConverter::convert('50.00001'));
$this->assertSame('5000', AmountConverter::convert('50.00011'));
$this->assertSame('5000', AmountConverter::convert('50.00111'));
// 100 dollars (100 U.S. dollars) + (0 U.S. cents)
$this->assertSame('10000', AmountConverter::convert(100));
$this->assertSame('10000', AmountConverter::convert('100'));
$this->assertSame('10000', AmountConverter::convert(100.0));
$this->assertSame('10000', AmountConverter::convert(100.00));
$this->assertSame('10000', AmountConverter::convert('100.00'));
$this->assertSame('10000', AmountConverter::convert(100.00001));
$this->assertSame('10000', AmountConverter::convert(100.00011));
$this->assertSame('10000', AmountConverter::convert(100.00111));
$this->assertSame('10000', AmountConverter::convert('100.00001'));
$this->assertSame('10000', AmountConverter::convert('100.00011'));
$this->assertSame('10000', AmountConverter::convert('100.00111'));
// 101 dollars (101 U.S. dollars) + (0 U.S. cents)
$this->assertSame('10100', AmountConverter::convert(101));
$this->assertSame('10100', AmountConverter::convert('101'));
$this->assertSame('10100', AmountConverter::convert(101.0));
$this->assertSame('10100', AmountConverter::convert(101.00));
$this->assertSame('10100', AmountConverter::convert('101.00'));
$this->assertSame('10100', AmountConverter::convert(101.00001));
$this->assertSame('10100', AmountConverter::convert(101.00011));
$this->assertSame('10100', AmountConverter::convert(101.00111));
$this->assertSame('10100', AmountConverter::convert('101.00001'));
$this->assertSame('10100', AmountConverter::convert('101.00011'));
$this->assertSame('10100', AmountConverter::convert('101.00111'));
// 1299.50 dollars (1299 U.S. dollars) + (50 U.S. cents)
$this->assertSame('129950', AmountConverter::convert(1299.5));
$this->assertSame('129950', AmountConverter::convert(1299.50));
$this->assertSame('129950', AmountConverter::convert('1299.5'));
$this->assertSame('129950', AmountConverter::convert('1299.50'));
$this->assertSame('129950', AmountConverter::convert(1299.50001));
$this->assertSame('129950', AmountConverter::convert(1299.500011));
$this->assertSame('129950', AmountConverter::convert(1299.500111));
$this->assertSame('129950', AmountConverter::convert(1299.501111));
$this->assertSame('129950', AmountConverter::convert('1299.50001'));
$this->assertSame('129950', AmountConverter::convert('1299.500011'));
$this->assertSame('129950', AmountConverter::convert('1299.500111'));
$this->assertSame('129950', AmountConverter::convert('1299.501111'));
}
}