File tree Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Expand file tree Collapse file tree 2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change 2
2
3
3
namespace UKFast \SDK ;
4
4
5
+ use DateTime ;
5
6
use GuzzleHttp \Client as HttpClient ;
6
7
use GuzzleHttp \Exception \ClientException ;
7
8
use GuzzleHttp \Exception \GuzzleException ;
@@ -282,6 +283,14 @@ public function apiToFriendly($item, $map)
282
283
*/
283
284
public function friendlyToApi ($ item , $ map )
284
285
{
285
- return $ this ->apiToFriendly ($ item , array_flip ($ map ));
286
+ $ item = $ this ->apiToFriendly ($ item , array_flip ($ map ));
287
+
288
+ array_walk_recursive ($ item , function (&$ value ) {
289
+ if (is_object ($ value ) && get_class ($ value ) === DateTime::class) {
290
+ $ value = $ value ->format (DateTime::ATOM );
291
+ }
292
+ });
293
+
294
+ return $ item ;
286
295
}
287
296
}
Original file line number Diff line number Diff line change 2
2
3
3
namespace Tests ;
4
4
5
+ use DateTime ;
5
6
use GuzzleHttp \Client as Guzzle ;
6
7
use GuzzleHttp \HandlerStack ;
7
8
use GuzzleHttp \Handler \MockHandler ;
@@ -446,6 +447,25 @@ public function maps_friendly_names_to_api_names()
446
447
], $ api );
447
448
}
448
449
450
+ /**
451
+ * @test
452
+ */
453
+ public function maps_friendly_names_to_api_names_with_datetime_objects ()
454
+ {
455
+ $ map = ['created_at ' => 'createdAt ' ];
456
+ $ api = (new Client )->friendlyToApi ([
457
+ 'id ' => 1 ,
458
+ 'createdAt ' => new DateTime ('2018-01-01T10:00:00+00:00 ' ),
459
+ 'name ' => 'Test ' ,
460
+ ], $ map );
461
+
462
+ $ this ->assertEquals ([
463
+ 'id ' => 1 ,
464
+ 'created_at ' => '2018-01-01T10:00:00+00:00 ' ,
465
+ 'name ' => 'Test ' ,
466
+ ], $ api );
467
+ }
468
+
449
469
/**
450
470
* @test
451
471
*/
You can’t perform that action at this time.
0 commit comments