File tree Expand file tree Collapse file tree 2 files changed +40
-0
lines changed
src/Illuminate/Http/Client Expand file tree Collapse file tree 2 files changed +40
-0
lines changed Original file line number Diff line number Diff line change @@ -393,6 +393,18 @@ public function withHeaders(array $headers)
393
393
});
394
394
}
395
395
396
+ /**
397
+ * Add the given header to the request.
398
+ *
399
+ * @param string $name
400
+ * @param mixed $value
401
+ * @return $this
402
+ */
403
+ public function withHeader ($ name , $ value )
404
+ {
405
+ return $ this ->withHeaders ([$ name => $ value ]);
406
+ }
407
+
396
408
/**
397
409
* Replace the given headers on the request.
398
410
*
Original file line number Diff line number Diff line change @@ -909,6 +909,34 @@ public function testItCanReplaceHeadersWhenNoHeadersYetSet()
909
909
});
910
910
}
911
911
912
+ public function testCanConfirmSingleStringHeader ()
913
+ {
914
+ $ this ->factory ->fake ();
915
+
916
+ $ this ->factory ->withHeader ('X-Test-Header ' , 'foo ' )->post ('http://foo.com/json ' );
917
+
918
+ $ this ->factory ->assertSent (function (Request $ request ) {
919
+ return $ request ->url () === 'http://foo.com/json ' &&
920
+ $ request ->hasHeaders ([
921
+ 'X-Test-Header ' => 'foo ' ,
922
+ ]);
923
+ });
924
+ }
925
+
926
+ public function testCanConfirmSingleArrayHeader ()
927
+ {
928
+ $ this ->factory ->fake ();
929
+
930
+ $ this ->factory ->withHeader ('X-Test-ArrayHeader ' , ['bar ' , 'baz ' ])->post ('http://foo.com/json ' );
931
+
932
+ $ this ->factory ->assertSent (function (Request $ request ) {
933
+ return $ request ->url () === 'http://foo.com/json ' &&
934
+ $ request ->hasHeaders ([
935
+ 'X-Test-ArrayHeader ' => ['bar ' , 'baz ' ],
936
+ ]);
937
+ });
938
+ }
939
+
912
940
public function testExceptionAccessorOnSuccess ()
913
941
{
914
942
$ resp = new Response (new Psr7Response ());
You can’t perform that action at this time.
0 commit comments