Skip to content

Commit 110798b

Browse files
committed
test: replace test class names
CURLRequestTest is the main file.
1 parent 5f35f88 commit 110798b

File tree

2 files changed

+41
-38
lines changed

2 files changed

+41
-38
lines changed

tests/system/HTTP/CURLRequestDoNotShareOptionsTest.php renamed to tests/system/HTTP/CURLRequestShareOptionsTest.php

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,14 @@
2323
use CURLFile;
2424

2525
/**
26+
* This test case is for the case where shareOptions is true.
27+
* The shareOptions should be set to false.
28+
*
2629
* @internal
2730
*
2831
* @group Others
2932
*/
30-
final class CURLRequestDoNotShareOptionsTest extends CIUnitTestCase
33+
final class CURLRequestShareOptionsTest extends CIUnitTestCase
3134
{
3235
private MockCURLRequest $request;
3336

@@ -45,7 +48,7 @@ protected function getRequest(array $options = []): MockCURLRequest
4548
$app = new App();
4649

4750
$config = new ConfigCURLRequest();
48-
$config->shareOptions = false;
51+
$config->shareOptions = true;
4952
Factories::injectMock('config', 'CURLRequest', $config);
5053

5154
return new MockCURLRequest(($app), $uri, new Response($app), $options);
@@ -226,23 +229,6 @@ public function testDefaultOptionsAreSharedBetweenRequests(): void
226229
$this->assertSame('CodeIgniter Framework v4', $request->curl_options[CURLOPT_USERAGENT]);
227230
}
228231

229-
public function testHeaderContentLengthNotSharedBetweenRequests(): void
230-
{
231-
$options = [
232-
'base_uri' => 'http://www.foo.com/api/v1/',
233-
];
234-
$request = $this->getRequest($options);
235-
236-
$request->post('example', [
237-
'form_params' => [
238-
'q' => 'keyword',
239-
],
240-
]);
241-
$request->get('example');
242-
243-
$this->assertNull($request->header('Content-Length'));
244-
}
245-
246232
/**
247233
* @backupGlobals enabled
248234
*/
@@ -960,21 +946,6 @@ public function testApplyBodyByOptions(): void
960946
$this->assertSame('name=George', $request->curl_options[CURLOPT_POSTFIELDS]);
961947
}
962948

963-
public function testBodyIsResetOnSecondRequest(): void
964-
{
965-
$request = $this->getRequest([
966-
'base_uri' => 'http://www.foo.com/api/v1/',
967-
'delay' => 100,
968-
]);
969-
$request->setBody('name=George');
970-
$request->setOutput('Hi there');
971-
972-
$request->post('answer');
973-
$request->post('answer');
974-
975-
$this->assertArrayNotHasKey(CURLOPT_POSTFIELDS, $request->curl_options);
976-
}
977-
978949
public function testResponseHeaders(): void
979950
{
980951
$request = $this->getRequest([
@@ -1094,6 +1065,7 @@ public function testJSONData(): void
10941065
$expected,
10951066
$this->request->curl_options[CURLOPT_POSTFIELDS]
10961067
);
1068+
$this->assertSame($expected, $this->request->getBody());
10971069
}
10981070

10991071
public function testSetJSON(): void
@@ -1112,6 +1084,8 @@ public function testSetJSON(): void
11121084
$expected,
11131085
$this->request->curl_options[CURLOPT_POSTFIELDS]
11141086
);
1087+
$this->assertSame($expected, $this->request->getBody());
1088+
11151089
$this->assertSame(
11161090
'Content-Type: application/json',
11171091
$this->request->curl_options[CURLOPT_HTTPHEADER][0]

tests/system/HTTP/CURLRequestTest.php

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ protected function getRequest(array $options = []): MockCURLRequest
4545
$app = new App();
4646

4747
$config = new ConfigCURLRequest();
48-
$config->shareOptions = true;
48+
$config->shareOptions = false;
4949
Factories::injectMock('config', 'CURLRequest', $config);
5050

5151
return new MockCURLRequest(($app), $uri, new Response($app), $options);
@@ -226,6 +226,23 @@ public function testDefaultOptionsAreSharedBetweenRequests(): void
226226
$this->assertSame('CodeIgniter Framework v4', $request->curl_options[CURLOPT_USERAGENT]);
227227
}
228228

229+
public function testHeaderContentLengthNotSharedBetweenRequests(): void
230+
{
231+
$options = [
232+
'base_uri' => 'http://www.foo.com/api/v1/',
233+
];
234+
$request = $this->getRequest($options);
235+
236+
$request->post('example', [
237+
'form_params' => [
238+
'q' => 'keyword',
239+
],
240+
]);
241+
$request->get('example');
242+
243+
$this->assertNull($request->header('Content-Length'));
244+
}
245+
229246
/**
230247
* @backupGlobals enabled
231248
*/
@@ -943,6 +960,21 @@ public function testApplyBodyByOptions(): void
943960
$this->assertSame('name=George', $request->curl_options[CURLOPT_POSTFIELDS]);
944961
}
945962

963+
public function testBodyIsResetOnSecondRequest(): void
964+
{
965+
$request = $this->getRequest([
966+
'base_uri' => 'http://www.foo.com/api/v1/',
967+
'delay' => 100,
968+
]);
969+
$request->setBody('name=George');
970+
$request->setOutput('Hi there');
971+
972+
$request->post('answer');
973+
$request->post('answer');
974+
975+
$this->assertArrayNotHasKey(CURLOPT_POSTFIELDS, $request->curl_options);
976+
}
977+
946978
public function testResponseHeaders(): void
947979
{
948980
$request = $this->getRequest([
@@ -1062,7 +1094,6 @@ public function testJSONData(): void
10621094
$expected,
10631095
$this->request->curl_options[CURLOPT_POSTFIELDS]
10641096
);
1065-
$this->assertSame($expected, $this->request->getBody());
10661097
}
10671098

10681099
public function testSetJSON(): void
@@ -1081,8 +1112,6 @@ public function testSetJSON(): void
10811112
$expected,
10821113
$this->request->curl_options[CURLOPT_POSTFIELDS]
10831114
);
1084-
$this->assertSame($expected, $this->request->getBody());
1085-
10861115
$this->assertSame(
10871116
'Content-Type: application/json',
10881117
$this->request->curl_options[CURLOPT_HTTPHEADER][0]

0 commit comments

Comments
 (0)