forked from codeigniter4/CodeIgniter4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCURLRequestShareOptionsTest.php
More file actions
81 lines (66 loc) · 2.25 KB
/
CURLRequestShareOptionsTest.php
File metadata and controls
81 lines (66 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
declare(strict_types=1);
/**
* This file is part of CodeIgniter 4 framework.
*
* (c) CodeIgniter Foundation <admin@codeigniter.com>
*
* For the full copyright and license information, please view
* the LICENSE file that was distributed with this source code.
*/
namespace CodeIgniter\HTTP;
use CodeIgniter\Config\Factories;
use CodeIgniter\Test\Mock\MockCURLRequest;
use Config\App;
use Config\CURLRequest as ConfigCURLRequest;
use PHPUnit\Framework\Attributes\Group;
/**
* This test case is for the case where shareOptions is true.
* The shareOptions should be set to false.
*
* @internal
*/
#[Group('Others')]
final class CURLRequestShareOptionsTest extends CURLRequestTest
{
protected function getRequest(array $options = [], ?array $shareConnectionOptions = null): MockCURLRequest
{
$uri = isset($options['baseURI']) ? new URI($options['baseURI']) : new URI();
$app = new App();
$config = new ConfigCURLRequest();
$config->shareOptions = true;
if ($shareConnectionOptions !== null) {
$config->shareConnectionOptions = $shareConnectionOptions;
}
Factories::injectMock('config', 'CURLRequest', $config);
return new MockCURLRequest(($app), $uri, new Response($app), $options);
}
public function testHeaderContentLengthNotSharedBetweenRequests(): void
{
$options = [
'baseURI' => 'http://www.foo.com/api/v1/',
];
$request = $this->getRequest($options);
$request->post('example', [
'form_params' => [
'q' => 'keyword',
],
]);
$request->get('example');
// The Content-Length header is shared!
$this->assertSame('9', $request->header('Content-Length')->getValue());
}
public function testBodyIsResetOnSecondRequest(): void
{
$request = $this->getRequest([
'baseURI' => 'http://www.foo.com/api/v1/',
'delay' => 100,
]);
$request->setBody('name=George');
$request->setOutput('Hi there');
$request->post('answer');
$request->post('answer');
// The body is not reset!
$this->assertArrayHasKey(CURLOPT_POSTFIELDS, $request->curl_options);
}
}