public function curl($source = null, $type = 'get', $fields = array())
{
$result = '';
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_URL, $source);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
if (strtolower($type) === 'post') {
curl_setopt($ch, CURLOPT_POST, true);
if (count($fields) !== 0) {
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($fields));
}
}
$result = curl_exec($ch);
if ($result === false) {
$result = curl_error($ch);
}
curl_close($ch);
return $result;
}
This is my curl function, I would like to do PHPUnit
test to check some other upload file function, therefore I need to simulate form post method with file in PHPUnit
, the problem is, curl
need to give domain name, of course I can get domain by $_SERVER
method, but in command line it won't work, how will you do unitest to test a file upload behavior.