Skip to content

Commit

Permalink
adding tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmedash95 committed Oct 2, 2022
1 parent e515b25 commit 3e8df38
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Reflection/ParametersAcceptorSelector.php
Expand Up @@ -728,10 +728,10 @@ private static function getCurlOptValueType(int $curlOpt): ?Type
];
foreach ($arrayOrStringConstants as $constName) {
if (defined($constName) && constant($constName) === $curlOpt) {
return TypeCombinator::union(
return new UnionType([
new StringType(),
new ArrayType(new MixedType(), new MixedType()),
);
]);
}
}

Expand Down
Expand Up @@ -1213,6 +1213,10 @@ public function testCurlSetOpt(): void
'Parameter #3 $value of function curl_setopt expects resource, string given.',
24,
],
[
'Parameter #3 $value of function curl_setopt expects array|string, int given.',
26,
],
]);
}

Expand Down
5 changes: 5 additions & 0 deletions tests/PHPStan/Rules/Functions/data/curl_setopt.php
Expand Up @@ -22,6 +22,8 @@ public function errors(int $i, string $s) {
curl_setopt($curl, CURLOPT_CONNECT_TO, $s);
// expecting resource
curl_setopt($curl, CURLOPT_FILE, $s);
// expecting string or array
curl_setopt($curl, CURLOPT_POSTFIELDS, $i);
}

/**
Expand All @@ -45,5 +47,8 @@ public function allGood(string $url, array $header) {
curl_setopt($curl, CURLOPT_FILE, $fp);
curl_setopt($curl, CURLOPT_HEADER, false);
curl_setopt($curl, CURLOPT_HTTPHEADER, array('Content-type: text/plain', 'Content-length: 100'));
curl_setopt($curl, CURLOPT_POSTFIELDS, array('foo' => 'bar'));
curl_setopt($curl, CURLOPT_POSTFIELDS, '');
curl_setopt($curl, CURLOPT_POSTFIELDS, 'para1=val1&para2=val2');
}
}

0 comments on commit 3e8df38

Please sign in to comment.