问题
I'm using PHPUnit to try to unit test some PHP files that are part of a web application I'm developing. I've got a WAMP server set up, and have set my php.ini file to have the curl extension installed. I've verified it's installed by checking phpinfo(), and curl does have a config section on the page, indicating it's installed.
When I run my entire web application starting from the index page, this php page I'm trying to test finds the curl_init() function without a problem.
When I run my unit test on the file, however, the it gives me the following error:
PHP Fatal error: Call to undefined function curl_init() in ...
Like I said, the file that calls curl_init() works great when run in the context of the whole application, but can't find it when it's being run alone by my PHPUnit tests. Does anyone know why this is happening? Does PHPUnit not know how to find the PHP extensions installed on my WAMP server?
回答1:
You need to add the Curl libraries to the command line PHP.ini.
You can probably just copy the file C:\wamp\bin\apache\Apache2.2.x\bin\php.ini
to c:\wamp\bin\php\php5.3.10\php.ini
(adjust for the actual directories on your system).
回答2:
Open your c:\wamp\bin\php\php5.x.x\php.ini
file and find:
;extension=php_curl.dll
Just uncomment it by removing the semicolon, such as:
extension=php_curl.dll
and save the file.
回答3:
The latest php.ini file will have
;extension=curl
so please remove ; and save works fine
来源:https://stackoverflow.com/questions/9621615/phpunit-call-to-undefined-function-curl-init-error