Skip to content

Commit c36a916

Browse files
committed
adjust and add curl getinfo tests
1 parent 032a292 commit c36a916

File tree

6 files changed

+87
-15
lines changed

6 files changed

+87
-15
lines changed

tests/PHPStan/Analyser/nsrt/curl_getinfo.php

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,17 @@ class Foo
99
{
1010
public function bar()
1111
{
12+
$curlGetInfoType = '(array{url: string, content_type: string|null, http_code: int, header_size: int, request_size: int, filetime: int, ssl_verify_result: int, redirect_count: int, total_time: float, namelookup_time: float, connect_time: float, pretransfer_time: float, size_upload: float, size_download: float, speed_download: float, speed_upload: float, download_content_length: float, upload_content_length: float, starttransfer_time: float, redirect_time: float, redirect_url: string, primary_ip: string, certinfo: list<array<string, string>>, primary_port: int, local_ip: string, local_port: int, http_version: int, protocol: int, ssl_verifyresult: int, scheme: string, appconnect_time_us: int, queue_time_us: int, connect_time_us: int, namelookup_time_us: int, pretransfer_time_us: int, redirect_time_us: int, starttransfer_time_us: int, posttransfer_time_us: int, total_time_us: int, request_header: string, effective_method: string, capath: string, cainfo: string, used_proxy: int, httpauth_used: int, proxyauth_used: int, conn_id: int}|false)';
13+
1214
$handle = new CurlHandle();
1315
assertType('mixed', curl_getinfo());
1416
assertType('mixed', CURL_GETINFO());
1517
assertType('mixed', CuRl_GeTiNfO());
1618
assertType('false', curl_getinfo($handle, 'Invalid Argument'));
17-
assertType('(array{url: string, content_type: string|null, http_code: int, header_size: int, request_size: int, filetime: int, ssl_verify_result: int, redirect_count: int, total_time: float, namelookup_time: float, connect_time: float, pretransfer_time: float, size_upload: float, size_download: float, speed_download: float, speed_upload: float, download_content_length: float, upload_content_length: float, starttransfer_time: float, redirect_time: float, redirect_url: string, primary_ip: string, certinfo: array<int, array<string, string>>, primary_port: int, local_ip: string, local_port: int, http_version: int, protocol: int, ssl_verifyresult: int, scheme: string}|false)', curl_getinfo($handle, PHP_INT_MAX));
19+
assertType($curlGetInfoType, curl_getinfo($handle, PHP_INT_MAX));
1820
assertType('false', curl_getinfo($handle, PHP_EOL));
19-
assertType('(array{url: string, content_type: string|null, http_code: int, header_size: int, request_size: int, filetime: int, ssl_verify_result: int, redirect_count: int, total_time: float, namelookup_time: float, connect_time: float, pretransfer_time: float, size_upload: float, size_download: float, speed_download: float, speed_upload: float, download_content_length: float, upload_content_length: float, starttransfer_time: float, redirect_time: float, redirect_url: string, primary_ip: string, certinfo: array<int, array<string, string>>, primary_port: int, local_ip: string, local_port: int, http_version: int, protocol: int, ssl_verifyresult: int, scheme: string}|false)', curl_getinfo($handle));
20-
assertType('(array{url: string, content_type: string|null, http_code: int, header_size: int, request_size: int, filetime: int, ssl_verify_result: int, redirect_count: int, total_time: float, namelookup_time: float, connect_time: float, pretransfer_time: float, size_upload: float, size_download: float, speed_download: float, speed_upload: float, download_content_length: float, upload_content_length: float, starttransfer_time: float, redirect_time: float, redirect_url: string, primary_ip: string, certinfo: array<int, array<string, string>>, primary_port: int, local_ip: string, local_port: int, http_version: int, protocol: int, ssl_verifyresult: int, scheme: string}|false)', curl_getinfo($handle, null));
21+
assertType($curlGetInfoType, curl_getinfo($handle));
22+
assertType($curlGetInfoType, curl_getinfo($handle, null));
2123
assertType('string', curl_getinfo($handle, CURLINFO_EFFECTIVE_URL));
2224
assertType('string', curl_getinfo($handle, 1048577)); // CURLINFO_EFFECTIVE_URL int value without using constant
2325
assertType('false', curl_getinfo($handle, 12345678)); // Non constant non CURLINFO_* int value
@@ -29,38 +31,39 @@ public function bar()
2931
assertType('float', curl_getinfo($handle, CURLINFO_STARTTRANSFER_TIME));
3032
assertType('int', curl_getinfo($handle, CURLINFO_REDIRECT_COUNT));
3133
assertType('float', curl_getinfo($handle, CURLINFO_REDIRECT_TIME));
32-
assertType('string', curl_getinfo($handle, CURLINFO_REDIRECT_URL));
34+
assertType('string|false', curl_getinfo($handle, CURLINFO_REDIRECT_URL));
3335
assertType('string', curl_getinfo($handle, CURLINFO_PRIMARY_IP));
3436
assertType('int', curl_getinfo($handle, CURLINFO_PRIMARY_PORT));
3537
assertType('string', curl_getinfo($handle, CURLINFO_LOCAL_IP));
3638
assertType('int', curl_getinfo($handle, CURLINFO_LOCAL_PORT));
37-
assertType('int', curl_getinfo($handle, CURLINFO_SIZE_UPLOAD));
38-
assertType('int', curl_getinfo($handle, CURLINFO_SIZE_DOWNLOAD));
39-
assertType('int', curl_getinfo($handle, CURLINFO_SPEED_DOWNLOAD));
40-
assertType('int', curl_getinfo($handle, CURLINFO_SPEED_UPLOAD));
39+
assertType('float', curl_getinfo($handle, CURLINFO_SIZE_UPLOAD));
40+
assertType('float', curl_getinfo($handle, CURLINFO_SIZE_DOWNLOAD));
41+
assertType('float', curl_getinfo($handle, CURLINFO_SPEED_DOWNLOAD));
42+
assertType('float', curl_getinfo($handle, CURLINFO_SPEED_UPLOAD));
4143
assertType('int', curl_getinfo($handle, CURLINFO_HEADER_SIZE));
4244
assertType('string|false', curl_getinfo($handle, CURLINFO_HEADER_OUT));
4345
assertType('int', curl_getinfo($handle, CURLINFO_REQUEST_SIZE));
4446
assertType('int', curl_getinfo($handle, CURLINFO_SSL_VERIFYRESULT));
4547
assertType('float', curl_getinfo($handle, CURLINFO_CONTENT_LENGTH_DOWNLOAD));
4648
assertType('float', curl_getinfo($handle, CURLINFO_CONTENT_LENGTH_UPLOAD));
4749
assertType('string|false', curl_getinfo($handle, CURLINFO_CONTENT_TYPE));
48-
assertType('string|false', curl_getinfo($handle, CURLINFO_PRIVATE));
50+
assertType('mixed', curl_getinfo($handle, CURLINFO_PRIVATE));
4951
assertType('int', curl_getinfo($handle, CURLINFO_RESPONSE_CODE));
52+
assertType('int', curl_getinfo($handle, CURLINFO_HTTP_CODE));;
5053
assertType('int', curl_getinfo($handle, CURLINFO_HTTP_CONNECTCODE));
5154
assertType('int', curl_getinfo($handle, CURLINFO_HTTPAUTH_AVAIL));
5255
assertType('int', curl_getinfo($handle, CURLINFO_PROXYAUTH_AVAIL));
5356
assertType('int', curl_getinfo($handle, CURLINFO_OS_ERRNO));
5457
assertType('int', curl_getinfo($handle, CURLINFO_NUM_CONNECTS));
55-
assertType('array<int, string>', curl_getinfo($handle, CURLINFO_SSL_ENGINES));
56-
assertType('array<int, string>', curl_getinfo($handle, CURLINFO_COOKIELIST));
58+
assertType('list<string>', curl_getinfo($handle, CURLINFO_SSL_ENGINES));
59+
assertType('list<string>', curl_getinfo($handle, CURLINFO_COOKIELIST));
5760
assertType('string|false', curl_getinfo($handle, CURLINFO_FTP_ENTRY_PATH));
5861
assertType('float', curl_getinfo($handle, CURLINFO_APPCONNECT_TIME));
59-
assertType('array<int, array<string, string>>', curl_getinfo($handle, CURLINFO_CERTINFO));
62+
assertType('list<array<string, string>>', curl_getinfo($handle, CURLINFO_CERTINFO));
6063
assertType('int', curl_getinfo($handle, CURLINFO_CONDITION_UNMET));
6164
assertType('int', curl_getinfo($handle, CURLINFO_RTSP_CLIENT_CSEQ));
6265
assertType('int', curl_getinfo($handle, CURLINFO_RTSP_CSEQ_RECV));
6366
assertType('int', curl_getinfo($handle, CURLINFO_RTSP_SERVER_CSEQ));
64-
assertType('int', curl_getinfo($handle, CURLINFO_RTSP_SESSION_ID));
67+
assertType('string|false', curl_getinfo($handle, CURLINFO_RTSP_SESSION_ID));
6568
}
6669
}

tests/PHPStan/Analyser/nsrt/curl_getinfo_7.3.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,15 @@
55
use CurlHandle;
66
use function PHPStan\Testing\assertType;
77

8-
class Foo {
8+
class Foo
9+
{
910
public function bar()
1011
{
1112
$handle = new CurlHandle();
1213
assertType('int', curl_getinfo($handle, CURLINFO_CONTENT_LENGTH_DOWNLOAD_T));
1314
assertType('int', curl_getinfo($handle, CURLINFO_CONTENT_LENGTH_UPLOAD_T));
1415
assertType('int', curl_getinfo($handle, CURLINFO_HTTP_VERSION));
15-
assertType('string', curl_getinfo($handle, CURLINFO_PROTOCOL));
16+
assertType('int', curl_getinfo($handle, CURLINFO_PROTOCOL));
1617
assertType('int', curl_getinfo($handle, CURLINFO_PROXY_SSL_VERIFYRESULT));
1718
assertType('string', curl_getinfo($handle, CURLINFO_SCHEME));
1819
assertType('int', curl_getinfo($handle, CURLINFO_SIZE_DOWNLOAD_T));
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php // lint >= 8.2
2+
3+
namespace CurlGetinfo82;
4+
5+
use CurlHandle;
6+
use function PHPStan\Testing\assertType;
7+
8+
class Foo
9+
{
10+
public function bar()
11+
{
12+
$handle = new CurlHandle();
13+
assertType('string', curl_getinfo($handle, CURLINFO_EFFECTIVE_METHOD));
14+
assertType('int', curl_getinfo($handle, CURLINFO_PROXY_ERROR));
15+
assertType('string|false', curl_getinfo($handle, CURLINFO_REFERER));
16+
assertType('int', curl_getinfo($handle, CURLINFO_RETRY_AFTER));
17+
}
18+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php // lint >= 8.3
2+
3+
namespace CurlGetinfo83;
4+
5+
use CurlHandle;
6+
use function PHPStan\Testing\assertType;
7+
8+
class Foo
9+
{
10+
public function bar()
11+
{
12+
$handle = new CurlHandle();
13+
assertType('string|false', curl_getinfo($handle, CURLINFO_CAINFO));
14+
assertType('string|false', curl_getinfo($handle, CURLINFO_CAPATH));
15+
}
16+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php // lint >= 8.4
2+
3+
namespace CurlGetinfo84;
4+
5+
use CurlHandle;
6+
use function PHPStan\Testing\assertType;
7+
8+
class Foo
9+
{
10+
public function bar()
11+
{
12+
$handle = new CurlHandle();
13+
assertType('int|false', curl_getinfo($handle, CURLINFO_POSTTRANSFER_TIME_T));
14+
}
15+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php // lint >= 8.5
2+
3+
namespace CurlGetinfo85;
4+
5+
use CurlHandle;
6+
use function PHPStan\Testing\assertType;
7+
8+
class Foo
9+
{
10+
public function bar()
11+
{
12+
$handle = new CurlHandle();
13+
assertType('int|false', curl_getinfo($handle, CURLINFO_QUEUE_TIME_T));
14+
assertType('int|false', curl_getinfo($handle, CURLINFO_USED_PROXY));
15+
assertType('int|false', curl_getinfo($handle, CURLINFO_HTTPAUTH_USED));
16+
assertType('int|false', curl_getinfo($handle, CURLINFO_PROXYAUTH_USED));
17+
assertType('int|false', curl_getinfo($handle, CURLINFO_CONN_ID));
18+
}
19+
}

0 commit comments

Comments
 (0)