Skip to content

Commit 9f03879

Browse files
committed
Rename methods
Request::run to Request::send Request::runMulti to Request::sendMulti
1 parent 728070c commit 9f03879

File tree

4 files changed

+21
-21
lines changed

4 files changed

+21
-21
lines changed

src/Client.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function createRequest(URL | string $url) : Request
4444
}
4545

4646
/**
47-
* Run the Request.
47+
* Send a Request.
4848
*
4949
* @param Request $request
5050
*
@@ -53,7 +53,7 @@ public function createRequest(URL | string $url) : Request
5353
*
5454
* @return Response
5555
*/
56-
public function run(Request $request) : Response
56+
public function send(Request $request) : Response
5757
{
5858
$handle = \curl_init();
5959
$options = $request->getOptions();
@@ -93,15 +93,15 @@ public function run(Request $request) : Response
9393
}
9494

9595
/**
96-
* Run multiple HTTP Requests.
96+
* Send multiple HTTP Requests.
9797
*
9898
* @param Request[] $requests An associative array of Request instances
9999
* with ids as keys
100100
*
101101
* @return Generator<Response|ResponseError> The Requests ids as keys and
102102
* its respective Response or ResponseError as values
103103
*/
104-
public function runMulti(array $requests) : Generator
104+
public function sendMulti(array $requests) : Generator
105105
{
106106
$multiHandle = \curl_multi_init();
107107
$handles = [];

src/Request.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,7 @@ public function setUserAgent(?string $userAgent = null) : static
550550
* Used to write data to files, databases, etc...
551551
*
552552
* NOTE: Using this function makes the Response body, returned in the
553-
* {@see Client::run()} method, be set with an empty string.
553+
* {@see Client::send()} method, be set with an empty string.
554554
*
555555
* @param callable $callback A callback with the response body $data chunk
556556
* as first argument and the CurlHandle as the second. Return is not

tests/ClientTest.php

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ public function testRun() : void
4040
{
4141
$request = new Request('https://www.google.com');
4242
$request->setHeader('Content-Type', 'text/html');
43-
$response = $this->client->run($request);
43+
$response = $this->client->send($request);
4444
self::assertSame($request, $response->getRequest());
4545
self::assertInstanceOf(Response::class, $response);
4646
self::assertGreaterThan(100, \strlen($response->getBody()));
4747
self::assertEmpty($response->getInfo());
4848
$request->setOption(\CURLOPT_RETURNTRANSFER, false);
4949
\ob_start(); // Avoid terminal output
5050
$request->setGetInfo();
51-
$response = $this->client->run($request);
51+
$response = $this->client->send($request);
5252
self::assertInstanceOf(Response::class, $response);
5353
self::assertSame('', $response->getBody());
5454
self::assertGreaterThan(100, \strlen((string) \ob_get_contents()));
@@ -61,17 +61,17 @@ public function testProtocolsAndReasons() : void
6161
$request = new Request('https://www.google.com');
6262
$request->setProtocol('HTTP/1.1');
6363
self::assertSame('HTTP/1.1', $request->getProtocol());
64-
$response = $this->client->run($request);
64+
$response = $this->client->send($request);
6565
self::assertSame('HTTP/1.1', $response->getProtocol());
6666
self::assertSame('OK', $response->getStatusReason());
6767
$request->setProtocol('HTTP/2.0');
6868
self::assertSame('HTTP/2.0', $request->getProtocol());
69-
$response = $this->client->run($request);
69+
$response = $this->client->send($request);
7070
self::assertSame('HTTP/2', $response->getProtocol());
7171
self::assertSame('OK', $response->getStatusReason());
7272
$request->setProtocol('HTTP/2');
7373
self::assertSame('HTTP/2', $request->getProtocol());
74-
$response = $this->client->run($request);
74+
$response = $this->client->send($request);
7575
self::assertSame('HTTP/2', $response->getProtocol());
7676
// HTTP/1.0 is failing:
7777
// OpenSSL SSL_read: error:0A000126:SSL routines::unexpected eof while reading, errno 0
@@ -87,19 +87,19 @@ public function testMethods() : void
8787
$request = new Request('https://www.google.com');
8888
$request->setMethod('post');
8989
self::assertSame('POST', $request->getMethod());
90-
$response = $this->client->run($request);
90+
$response = $this->client->send($request);
9191
self::assertInstanceOf(Response::class, $response);
9292
$request->setMethod('put');
9393
self::assertSame('PUT', $request->getMethod());
94-
$response = $this->client->run($request);
94+
$response = $this->client->send($request);
9595
self::assertInstanceOf(Response::class, $response);
9696
}
9797

9898
public function testRunError() : void
9999
{
100100
$request = new Request('http://domain.tld');
101101
try {
102-
$this->client->run($request);
102+
$this->client->send($request);
103103
} catch (RequestException $exception) {
104104
$expected = \str_starts_with($exception->getMessage(), 'Could')
105105
? 0
@@ -123,7 +123,7 @@ public function testRunErrorWithInfo() : void
123123
$request = new Request('http://domain.tld');
124124
$request->setGetInfo();
125125
try {
126-
$this->client->run($request);
126+
$this->client->send($request);
127127
} catch (RequestException $exception) {
128128
self::assertSame(0, $exception->getInfo()['http_code']);
129129
}
@@ -138,7 +138,7 @@ public function testRunWithRequestDownloadFunction() : void
138138
self::assertInstanceOf(\CurlHandle::class, $handle);
139139
$page .= $data;
140140
});
141-
$response = $this->client->run($request);
141+
$response = $this->client->send($request);
142142
self::assertSame('', $response->getBody());
143143
self::assertStringContainsString('<!doctype html>', $page);
144144
self::assertStringContainsString('</html>', $page);
@@ -159,7 +159,7 @@ public function testRunMulti() : void
159159
'req3' => $req3,
160160
];
161161
$finished = [];
162-
$responses = $this->client->runMulti($requests);
162+
$responses = $this->client->sendMulti($requests);
163163
while ($responses->valid()) {
164164
$key = $responses->key();
165165
self::assertArrayHasKey($key, $requests);
@@ -181,7 +181,7 @@ public function testRunMultiGettingResponseInfo() : void
181181
];
182182
$requests[0]->setGetInfo();
183183
$requests[1]->setGetInfo();
184-
$responses = $this->client->runMulti($requests);
184+
$responses = $this->client->sendMulti($requests);
185185
$returned = [];
186186
while ($responses->valid()) {
187187
$key = $responses->key();
@@ -205,7 +205,7 @@ public function testResponseError() : void
205205
3 => new Request('https://aplus-framework.com/xxx'),
206206
];
207207
$responses = [];
208-
foreach ($this->client->runMulti($requests) as $id => $response) {
208+
foreach ($this->client->sendMulti($requests) as $id => $response) {
209209
$responses[$id] = $response;
210210
}
211211
self::assertInstanceOf(Response::class, $responses[1]);
@@ -225,7 +225,7 @@ public function testResponseErrorToString() : void
225225
$requests = [
226226
new Request('https://aplus-framework.tld'),
227227
];
228-
foreach ($this->client->runMulti($requests) as $response) {
228+
foreach ($this->client->sendMulti($requests) as $response) {
229229
self::assertInstanceOf(ResponseError::class, $response);
230230
self::assertSame(
231231
'Error 6: Could not resolve host: aplus-framework.tld',

tests/RequestTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ public function testDownloadFileAlreadyExistsOverwrite() : void
340340
$request->setDownloadFile($filename, true);
341341
self::assertFileDoesNotExist($filename);
342342
$client = new Client();
343-
$client->run($request);
343+
$client->send($request);
344344
self::assertFileExists($filename);
345345
self::assertStringContainsString(
346346
'Aplus Framework',
@@ -356,7 +356,7 @@ public function testDownloadFile() : void
356356
$request->setDownloadFile($filename);
357357
self::assertFileDoesNotExist($filename);
358358
$client = new Client();
359-
$client->run($request);
359+
$client->send($request);
360360
self::assertFileExists($filename);
361361
self::assertStringContainsString(
362362
'Aplus Framework',

0 commit comments

Comments
 (0)