-
Notifications
You must be signed in to change notification settings - Fork 9.4k
/
Copy pathCurlTest.php
82 lines (72 loc) · 2.12 KB
/
CurlTest.php
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
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);
namespace Magento\Framework\HTTP\Test\Unit\Client;
use Magento\Framework\HTTP\Client\Curl;
use PHPUnit\Framework\TestCase;
/**
* Test HTTP client based on cUrl.
*/
class CurlTest extends TestCase
{
/**
* Check that HTTP client can be used only for HTTP.
*/
public function testInvalidProtocol()
{
$this->expectException('Exception');
$this->expectExceptionMessageMatches('/Protocol .?telnet.? not supported or disabled in libcurl/');
$client = new Curl();
$client->get('telnet://127.0.0.1/test');
}
/**
* Check the HTTP client ability to parse headers case-insensitive.
*/
public function testParseHeaders()
{
// Prepare protected parseHeaders method
$curl = new Curl();
$parseHeaders = new \ReflectionMethod(
$curl,
'parseHeaders'
);
$parseHeaders->setAccessible(true);
// Parse headers
foreach ($this->headersDataProvider() as $header) {
$parseHeaders->invoke($curl, null, $header);
}
// Validate headers
$headers = $curl->getHeaders();
$this->assertIsArray($headers);
$this->assertEquals([
'Content-Type' => 'text/html; charset=utf-8',
'Set-Cookie' => [
'Normal=OK',
'Uppercase=OK',
'Lowercase=OK',
]
], $headers);
// Validate status
$status = $curl->getStatus();
$this->assertIsInt($status);
$this->assertEquals(200, $status);
// Validate cookies
$cookies = $curl->getCookies();
$this->assertIsArray($cookies);
$this->assertEquals([
'Normal' => 'OK',
'Uppercase' => 'OK',
'Lowercase' => 'OK',
], $cookies);
}
/**
* @return array
*/
public function headersDataProvider()
{
return array_filter(explode(PHP_EOL, file_get_contents(__DIR__ . '/_files/curl_headers.txt')));
}
}