forked from codeigniter4/CodeIgniter4
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOutgoingRequestTest.php
More file actions
111 lines (89 loc) · 3.42 KB
/
Copy pathOutgoingRequestTest.php
File metadata and controls
111 lines (89 loc) · 3.42 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
<?php
/**
* 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\Test\CIUnitTestCase;
/**
* @internal
*
* @group Others
*/
final class OutgoingRequestTest extends CIUnitTestCase
{
public function testCreateWithHeader()
{
$uri = new URI('https://example.com/');
$headers = ['User-Agent' => 'Mozilla/5.0'];
$request = new OutgoingRequest('GET', $uri, $headers);
$this->assertSame('Mozilla/5.0', $request->header('User-Agent')->getValue());
}
public function testGetUri()
{
$uri = new URI('https://example.com/');
$request = new OutgoingRequest('GET', $uri);
$this->assertSame($uri, $request->getUri());
}
public function testWithMethod()
{
$uri = new URI('https://example.com/');
$request = new OutgoingRequest('GET', $uri);
$newRequest = $request->withMethod('POST');
$this->assertSame('GET', strtoupper($request->getMethod()));
$this->assertSame('POST', strtoupper($newRequest->getMethod()));
}
public function testWithUri()
{
$uri = new URI('https://example.com/');
$request = new OutgoingRequest('GET', $uri);
$newUri = new URI('https://example.jp/');
$newRequest = $request->withUri($newUri);
$this->assertSame('example.jp', $newRequest->header('Host')->getValue());
}
/**
* If the Host header is missing or empty, and the new URI contains
* a host component, this method MUST update the Host header in the returned
* request.
* https://www.php-fig.org/psr/psr-7/#32-psrhttpmessagerequestinterface
*/
public function testWithUriPreserveHostHostHeaderIsMissingAndNewUriContainsHost()
{
$uri = new URI();
$request = new OutgoingRequest('GET', $uri);
$newUri = new URI('https://example.com/');
$newRequest = $request->withUri($newUri, true);
$this->assertSame('example.com', $newRequest->header('Host')->getValue());
}
/**
* If the Host header is missing or empty, and the new URI does not contain a
* host component, this method MUST NOT update the Host header in the returned
* request.
* https://www.php-fig.org/psr/psr-7/#32-psrhttpmessagerequestinterface
*/
public function testWithUriPreserveHostHostHeaderIsMissingAndNewUriDoesNotContainsHost()
{
$uri = new URI();
$request = new OutgoingRequest('GET', $uri);
$newUri = new URI();
$newRequest = $request->withUri($newUri, true);
$this->assertSame($request->header('Host'), $newRequest->header('Host'));
}
/**
* If a Host header is present and non-empty, this method MUST NOT update
* the Host header in the returned request.
* https://www.php-fig.org/psr/psr-7/#32-psrhttpmessagerequestinterface
*/
public function testWithUriPreserveHostHostHostIsNonEmpty()
{
$uri = new URI('https://example.com/');
$request = new OutgoingRequest('GET', $uri);
$newUri = new URI('https://example.jp/');
$newRequest = $request->withUri($newUri, true);
$this->assertSame('example.com', $newRequest->header('Host')->getValue());
}
}