Skip to content

Commit

Permalink
formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Feb 18, 2020
1 parent 4237cab commit 67f8176
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 35 deletions.
55 changes: 23 additions & 32 deletions src/Illuminate/Http/Client/ResponseSequence.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,75 +25,66 @@ public function __construct(array $responses)
/**
* Push a response to the sequence.
*
* @param mixed $response
* @return $this
*/
public function pushResponse($response)
{
$this->responses[] = $response;

return $this;
}

/**
* Push an empty response to the sequence.
*
* @param string|array $body
* @param int $status
* @param array $headers
* @return $this
*/
public function pushEmptyResponse($status = 200, $headers = [])
public function push($body = '', int $status = 200, array $headers = [])
{
if (is_array($body)) {
return $this->pushResponse(
Factory::response(json_encode($body), $status, $headers)
);
}

return $this->pushResponse(
Factory::response('', $status, $headers)
Factory::response($body, $status, $headers)
);
}

/**
* Push response with a string body to the sequence.
* Push a response with the given status code to the sequence.
*
* @param string $string
* @param int $status
* @param array $headers
* @return $this
*/
public function pushString($string, $status = 200, $headers = [])
public function pushStatus(int $status, array $headers = [])
{
return $this->pushResponse(
Factory::response($string, $status, $headers)
Factory::response('', $status, $headers)
);
}

/**
* Push response with a json body to the sequence.
* Push response with the contents of a file as the body to the sequence.
*
* @param array $data
* @param string $filePath
* @param int $status
* @param array $headers
* @return $this
*/
public function pushJson(array $data, $status = 200, $headers = [])
public function pushFile(string $filePath, int $status = 200, array $headers = [])
{
$string = file_get_contents($filePath);

return $this->pushResponse(
Factory::response(json_encode($data), $status, $headers)
Factory::response($string, $status, $headers)
);
}

/**
* Push response with the contents of a file as the body to the sequence.
* Push a response to the sequence.
*
* @param string $filePath
* @param int $status
* @param array $headers
* @param mixed $response
* @return $this
*/
public function pushFile($filePath, $status = 200, $headers = [])
public function pushResponse($response)
{
$string = file_get_contents($filePath);
$this->responses[] = $response;

return $this->pushResponse(
Factory::response($string, $status, $headers)
);
return $this;
}

/**
Expand Down
6 changes: 3 additions & 3 deletions tests/Http/HttpClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,10 +126,10 @@ public function testSequenceBuilder()

$factory->fake([
'*' => Factory::sequence()
->pushString('Ok', 201)
->pushJson(['fact' => 'Cats are great!'])
->push('Ok', 201)
->push(['fact' => 'Cats are great!'])
->pushFile(__DIR__.'/fixtures/test.txt')
->pushEmptyResponse(403),
->pushStatus(403),
]);

/** @var PendingRequest $factory */
Expand Down

0 comments on commit 67f8176

Please sign in to comment.