Skip to content

Commit 67f8176

Browse files
committed
formatting
1 parent 4237cab commit 67f8176

File tree

2 files changed

+26
-35
lines changed

2 files changed

+26
-35
lines changed

src/Illuminate/Http/Client/ResponseSequence.php

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,75 +25,66 @@ public function __construct(array $responses)
2525
/**
2626
* Push a response to the sequence.
2727
*
28-
* @param mixed $response
29-
* @return $this
30-
*/
31-
public function pushResponse($response)
32-
{
33-
$this->responses[] = $response;
34-
35-
return $this;
36-
}
37-
38-
/**
39-
* Push an empty response to the sequence.
40-
*
28+
* @param string|array $body
4129
* @param int $status
4230
* @param array $headers
4331
* @return $this
4432
*/
45-
public function pushEmptyResponse($status = 200, $headers = [])
33+
public function push($body = '', int $status = 200, array $headers = [])
4634
{
35+
if (is_array($body)) {
36+
return $this->pushResponse(
37+
Factory::response(json_encode($body), $status, $headers)
38+
);
39+
}
40+
4741
return $this->pushResponse(
48-
Factory::response('', $status, $headers)
42+
Factory::response($body, $status, $headers)
4943
);
5044
}
5145

5246
/**
53-
* Push response with a string body to the sequence.
47+
* Push a response with the given status code to the sequence.
5448
*
55-
* @param string $string
5649
* @param int $status
5750
* @param array $headers
5851
* @return $this
5952
*/
60-
public function pushString($string, $status = 200, $headers = [])
53+
public function pushStatus(int $status, array $headers = [])
6154
{
6255
return $this->pushResponse(
63-
Factory::response($string, $status, $headers)
56+
Factory::response('', $status, $headers)
6457
);
6558
}
6659

6760
/**
68-
* Push response with a json body to the sequence.
61+
* Push response with the contents of a file as the body to the sequence.
6962
*
70-
* @param array $data
63+
* @param string $filePath
7164
* @param int $status
7265
* @param array $headers
7366
* @return $this
7467
*/
75-
public function pushJson(array $data, $status = 200, $headers = [])
68+
public function pushFile(string $filePath, int $status = 200, array $headers = [])
7669
{
70+
$string = file_get_contents($filePath);
71+
7772
return $this->pushResponse(
78-
Factory::response(json_encode($data), $status, $headers)
73+
Factory::response($string, $status, $headers)
7974
);
8075
}
8176

8277
/**
83-
* Push response with the contents of a file as the body to the sequence.
78+
* Push a response to the sequence.
8479
*
85-
* @param string $filePath
86-
* @param int $status
87-
* @param array $headers
80+
* @param mixed $response
8881
* @return $this
8982
*/
90-
public function pushFile($filePath, $status = 200, $headers = [])
83+
public function pushResponse($response)
9184
{
92-
$string = file_get_contents($filePath);
85+
$this->responses[] = $response;
9386

94-
return $this->pushResponse(
95-
Factory::response($string, $status, $headers)
96-
);
87+
return $this;
9788
}
9889

9990
/**

tests/Http/HttpClientTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,10 @@ public function testSequenceBuilder()
126126

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

135135
/** @var PendingRequest $factory */

0 commit comments

Comments
 (0)