Skip to content

Commit

Permalink
Add minor changes to HTTP client.
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmichot authored and taylorotwell committed Mar 3, 2020
1 parent d583740 commit 39f1da2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 12 deletions.
15 changes: 12 additions & 3 deletions src/Illuminate/Http/Client/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
namespace Illuminate\Http\Client;

use Closure;
use GuzzleHttp\Psr7\Response as Psr7Response;
use Illuminate\Support\Str;
use Illuminate\Support\Traits\Macroable;
use PHPUnit\Framework\Assert as PHPUnit;
use function GuzzleHttp\Promise\promise_for;

class Factory
{
Expand All @@ -16,7 +18,7 @@ class Factory
/**
* The stub callables that will handle requests.
*
* @var \Illuminate\Support\Collection|null
* @var \Illuminate\Support\Collection
*/
protected $stubCallbacks;

Expand All @@ -34,6 +36,13 @@ class Factory
*/
protected $responseSequences = [];

/**
* The record array.
*
* @var array
*/
protected $recorded;

/**
* Create a new factory instance.
*
Expand All @@ -60,7 +69,7 @@ public static function response($body = null, $status = 200, $headers = [])
$headers['Content-Type'] = 'application/json';
}

return \GuzzleHttp\Promise\promise_for(new \GuzzleHttp\Psr7\Response($status, $headers, $body));
return promise_for(new Psr7Response($status, $headers, $body));
}

/**
Expand Down Expand Up @@ -95,7 +104,7 @@ public function fake($callback = null)
$this->stubUrl($url, $callable);
}

return;
return $this;
}

$this->stubCallbacks = $this->stubCallbacks->merge(collect([
Expand Down
3 changes: 2 additions & 1 deletion src/Illuminate/Http/Client/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function __construct($request)
/**
* Get the request method.
*
* @return strign
* @return string
*/
public function method()
{
Expand Down Expand Up @@ -70,6 +70,7 @@ public function hasHeader($key, $value = null)
/**
* Get the values for the header with the given name.
*
* @param string $key
* @return array
*/
public function header($key)
Expand Down
7 changes: 5 additions & 2 deletions src/Illuminate/Http/Client/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public function json()
/**
* Get a header from the response.
*
* @param string $header
* @return string
*/
public function header(string $header)
Expand Down Expand Up @@ -134,7 +135,7 @@ public function redirect()
}

/**
* Detemine if the response indicates a client error occurred.
* Determine if the response indicates a client error occurred.
*
* @return bool
*/
Expand All @@ -144,7 +145,7 @@ public function clientError()
}

/**
* Detemine if the response indicates a server error occurred.
* Determine if the response indicates a server error occurred.
*
* @return bool
*/
Expand Down Expand Up @@ -177,6 +178,8 @@ public function toPsrResponse()
* Throw an exception if a server or client error occurred.
*
* @return $this
*
* @throws \Illuminate\Http\Client\RequestException
*/
public function throw()
{
Expand Down
8 changes: 2 additions & 6 deletions src/Illuminate/Http/Client/ResponseSequence.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ResponseSequence
protected $failWhenEmpty = true;

/**
* The repsonse that should be returned when the sequence is empty.
* The response that should be returned when the sequence is empty.
*
* @var \GuzzleHttp\Promise\PromiseInterface
*/
Expand All @@ -48,11 +48,7 @@ public function __construct(array $responses)
*/
public function push($body = '', int $status = 200, array $headers = [])
{
if (is_array($body)) {
return $this->pushResponse(
Factory::response(json_encode($body), $status, $headers)
);
}
$body = is_array($body) ? json_encode($body) : $body;

return $this->pushResponse(
Factory::response($body, $status, $headers)
Expand Down

0 comments on commit 39f1da2

Please sign in to comment.