Skip to content

Commit 4b4cb59

Browse files
committed
Add tests
1 parent f933ac7 commit 4b4cb59

File tree

3 files changed

+31
-11
lines changed

3 files changed

+31
-11
lines changed

src/Reflection/ParametersAcceptorSelector.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -936,11 +936,13 @@ private static function getCurlOptValueType(int $curlOpt): ?Type
936936
];
937937
foreach ($nullableStringConstants as $constName) {
938938
if (defined($constName) && constant($constName) === $curlOpt) {
939-
return TypeCombinator::intersect(
939+
return new UnionType([
940940
new NullType(),
941-
new StringType(),
942-
new AccessoryNonEmptyStringType(),
943-
);
941+
TypeCombinator::intersect(
942+
new StringType(),
943+
new AccessoryNonEmptyStringType(),
944+
),
945+
]);
944946
}
945947
}
946948

tests/PHPStan/Rules/Functions/CallToFunctionParametersRuleTest.php

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,33 +1314,45 @@ public function testCurlSetOpt(): void
13141314
'Parameter #3 $value of function curl_setopt expects array<int, string>, int given.',
13151315
17,
13161316
],
1317+
[
1318+
'Parameter #3 $value of function curl_setopt expects non-empty-string, null given.',
1319+
18,
1320+
],
13171321
[
13181322
'Parameter #3 $value of function curl_setopt expects bool, int given.',
1319-
19,
1323+
20,
13201324
],
13211325
[
13221326
'Parameter #3 $value of function curl_setopt expects bool, string given.',
1323-
20,
1327+
21,
13241328
],
13251329
[
13261330
'Parameter #3 $value of function curl_setopt expects int, string given.',
1327-
22,
1331+
23,
13281332
],
13291333
[
13301334
'Parameter #3 $value of function curl_setopt expects array, string given.',
1331-
24,
1335+
25,
13321336
],
13331337
[
13341338
'Parameter #3 $value of function curl_setopt expects resource, string given.',
1335-
26,
1339+
27,
13361340
],
13371341
[
13381342
'Parameter #3 $value of function curl_setopt expects array|string, int given.',
1339-
28,
1343+
29,
1344+
],
1345+
[
1346+
'Parameter #3 $value of function curl_setopt expects non-empty-string, \'\' given.',
1347+
31,
1348+
],
1349+
[
1350+
'Parameter #3 $value of function curl_setopt expects non-empty-string|null, \'\' given.',
1351+
32,
13401352
],
13411353
[
13421354
'Parameter #3 $value of function curl_setopt expects array<int, string>, array<string, string> given.',
1343-
67,
1355+
73,
13441356
],
13451357
]);
13461358
}

tests/PHPStan/Rules/Functions/data/curl_setopt.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ public function errors(int $i, string $s) {
1515
// expecting string
1616
curl_setopt($curl, CURLOPT_URL, $i);
1717
curl_setopt($curl, CURLOPT_HTTPHEADER, $i);
18+
curl_setopt($curl, CURLOPT_ABSTRACT_UNIX_SOCKET, null);
1819
// expecting bool
1920
curl_setopt($curl, CURLOPT_AUTOREFERER, $i);
2021
curl_setopt($curl, CURLOPT_RETURNTRANSFER, $s);
@@ -26,6 +27,9 @@ public function errors(int $i, string $s) {
2627
curl_setopt($curl, CURLOPT_FILE, $s);
2728
// expecting string or array
2829
curl_setopt($curl, CURLOPT_POSTFIELDS, $i);
30+
// expecting non empty string
31+
curl_setopt($curl, CURLOPT_URL, '');
32+
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, '');
2933
}
3034

3135
/**
@@ -41,6 +45,8 @@ public function allGood(string $url, array $header) {
4145
curl_setopt($curl, CURLOPT_AUTOREFERER, true);
4246
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
4347
curl_setopt($curl, CURLOPT_TIMEOUT, 10);
48+
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST');
49+
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, null);
4450

4551
$fp = fopen("example_homepage.txt", "w");
4652
if ($fp === false) {

0 commit comments

Comments
 (0)