Skip to content

Commit

Permalink
Merge pull request #60 from kitetail/add-configure-method-to-pending-…
Browse files Browse the repository at this point in the history
…zttp-response

Add ability to set configuration all at once
  • Loading branch information
adamwathan authored Mar 11, 2018
2 parents 9c5508e + c95d154 commit 3875188
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/Zttp.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@ static function new(...$args)
return new self(...$args);
}

function withOptions($options)
{
return tap($this, function ($request) use ($options) {
return $this->options = array_merge_recursive($this->options, $options);
});
}

function withoutRedirecting()
{
return tap($this, function ($request) {
Expand Down Expand Up @@ -174,6 +181,7 @@ function buildHandlerStack()
$stack->push($this->buildBeforeSendingHandler());
});
}

function buildBeforeSendingHandler()
{
return function ($handler) {
Expand Down
16 changes: 16 additions & 0 deletions tests/ZttpTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,22 @@ function query_parameters_in_urls_can_be_combined_with_array_parameters()
], $response->json());
}

/** @test */
function options_can_be_set_all_at_once()
{
$response = Zttp::withOptions([
'headers' => [
'accept' => ['text/xml'],
]
])->get($this->url('/get'));

$this->assertArraySubset([
'headers' => [
'accept' => ['text/xml'],
]
], $response->json());
}

/** @test */
function post_content_is_json_by_default()
{
Expand Down

0 comments on commit 3875188

Please sign in to comment.