@@ -481,6 +481,57 @@ public function toArray(): array
481
481
});
482
482
}
483
483
484
+ public function testCanSendJsonDataWithStringable ()
485
+ {
486
+ $ this ->factory ->fake ();
487
+
488
+ $ this ->factory ->withHeaders ([
489
+ 'X-Test-Header ' => 'foo ' ,
490
+ 'X-Test-ArrayHeader ' => ['bar ' , 'baz ' ],
491
+ ])->post ('http://foo.com/json ' , [
492
+ 'name ' => Str::of ('Taylor ' ),
493
+ ]);
494
+
495
+ $ this ->factory ->assertSent (function (Request $ request ) {
496
+ return $ request ->url () === 'http://foo.com/json ' &&
497
+ $ request ->hasHeader ('Content-Type ' , 'application/json ' ) &&
498
+ $ request ->hasHeader ('X-Test-Header ' , 'foo ' ) &&
499
+ $ request ->hasHeader ('X-Test-ArrayHeader ' , ['bar ' , 'baz ' ]) &&
500
+ $ request ['name ' ] === 'Taylor ' ;
501
+ });
502
+ }
503
+
504
+ public function testCanSendFormDataWithStringable ()
505
+ {
506
+ $ this ->factory ->fake ();
507
+
508
+ $ this ->factory ->asForm ()->post ('http://foo.com/form ' , [
509
+ 'name ' => Str::of ('Taylor ' ),
510
+ 'title ' => 'Laravel Developer ' ,
511
+ ]);
512
+
513
+ $ this ->factory ->assertSent (function (Request $ request ) {
514
+ return $ request ->url () === 'http://foo.com/form ' &&
515
+ $ request ->hasHeader ('Content-Type ' , 'application/x-www-form-urlencoded ' ) &&
516
+ $ request ['name ' ] === 'Taylor ' ;
517
+ });
518
+ }
519
+
520
+ public function testCanSendFormDataWithStringableInArrays ()
521
+ {
522
+ $ this ->factory ->fake ();
523
+
524
+ $ this ->factory ->asForm ()->post ('http://foo.com/form ' , [
525
+ 'posts ' => [['title ' => Str::of ('Taylor ' )]],
526
+ ]);
527
+
528
+ $ this ->factory ->assertSent (function (Request $ request ) {
529
+ return $ request ->url () === 'http://foo.com/form ' &&
530
+ $ request ->hasHeader ('Content-Type ' , 'application/x-www-form-urlencoded ' ) &&
531
+ $ request ['posts ' ][0 ]['title ' ] === 'Taylor ' ;
532
+ });
533
+ }
534
+
484
535
public function testRecordedCallsAreEmptiedWhenFakeIsCalled ()
485
536
{
486
537
$ this ->factory ->fake ([
@@ -800,6 +851,32 @@ public function testWithQueryParametersAllowsOverridingParameterOnRequest()
800
851
});
801
852
}
802
853
854
+ public function testWithStringableQueryParameters ()
855
+ {
856
+ $ this ->factory ->fake ();
857
+
858
+ $ this ->factory ->withQueryParameters (
859
+ ['foo ' => Str::of ('bar ' ),]
860
+ )->get ('https://laravel.com ' );
861
+
862
+ $ this ->factory ->assertSent (function (Request $ request ) {
863
+ return $ request ->url () === 'https://laravel.com?foo=bar ' ;
864
+ });
865
+ }
866
+
867
+ public function testWithArrayStringableQueryParameters ()
868
+ {
869
+ $ this ->factory ->fake ();
870
+
871
+ $ this ->factory ->withQueryParameters (
872
+ ['foo ' => ['bar ' , Str::of ('baz ' )]],
873
+ )->get ('https://laravel.com ' );
874
+
875
+ $ this ->factory ->assertSent (function (Request $ request ) {
876
+ return $ request ->url () === 'https://laravel.com?foo%5B0%5D=bar&foo%5B1%5D=baz ' ;
877
+ });
878
+ }
879
+
803
880
public function testGetWithArrayQueryParam ()
804
881
{
805
882
$ this ->factory ->fake ();
0 commit comments