1
1
<?php
2
2
3
+ use Illuminate \Http \Client \PendingRequest ;
3
4
use Illuminate \Support \Facades \Bus ;
4
5
use Illuminate \Support \Facades \Config ;
5
6
use Illuminate \Support \Facades \Http ;
20
21
21
22
$ user = User::factory ()->create ();
22
23
24
+ Http::shouldReceive ('retry ' )
25
+ ->andReturnSelf ();
23
26
Http::shouldReceive ('get ' )
24
27
->with ('http://ip-api.com/json/127.0.0.1 ' )
25
28
->once ()
57
60
'last_login_at ' => now ()->subDays (5 ),
58
61
]);
59
62
63
+ Http::shouldReceive ('retry ' )
64
+ ->andReturnSelf ();
60
65
Http::shouldReceive ('get ' )
61
66
->with ('http://ip-api.com/json/ ' .$ login ->ip_address )
62
67
->once ()
94
99
],
95
100
]);
96
101
102
+ Http::shouldReceive ('retry ' )
103
+ ->andReturnSelf ();
97
104
Http::shouldReceive ('get ' )
98
105
->with ('http://ip-api.com/json/127.0.0.1 ' )
99
106
->once ()
131
138
],
132
139
]);
133
140
141
+ Http::shouldReceive ('retry ' )
142
+ ->andReturnSelf ();
134
143
Http::shouldReceive ('get ' )
135
144
->with ('http://ip-api.com/json/127.0.0.1 ' )
136
145
->once ()
187
196
],
188
197
]);
189
198
199
+ Http::shouldReceive ('retry ' )
200
+ ->andReturnSelf ();
190
201
Http::shouldReceive ('get ' )
191
202
->with ('http://ip-api.com/json/128.0.0.1 ' )
192
203
->once ()
231
242
IPAddress::process ([
232
243
'ipAddress ' => '127.0.0.1 ' ,
233
244
]);
234
- })->expectException (IPAddressDriverMissingException::class);
245
+ })->expectException (IPAddressDriverMissingException::class);
246
+
247
+ it ('fails if no ip location data ' , function () {
248
+ $ login = Login::factory ()->create ();
249
+
250
+ Http::shouldReceive ('retry ' )
251
+ ->andReturnSelf ();
252
+ Http::shouldReceive ('get ' )
253
+ ->with ('http://ip-api.com/json/1234567890 ' );
254
+ Http::shouldReceive ('json ' )
255
+ ->never ();
256
+
257
+ IPAddress::process ([
258
+ 'ipAddress ' => '1234567890 ' ,
259
+ 'userId ' => $ login ->user_id ,
260
+ 'userType ' => $ login ->user_type ,
261
+ ]);
262
+ })->expectException (Exception::class, 'Failed to get IP location data for: 1234567890 ' );
0 commit comments