简体   繁体   English

PHPUnit - 调用未定义的函数curl_init()错误

[英]PHPUnit - Call to undefined function curl_init() error

I'm using PHPUnit to try to unit test some PHP files that are part of a web application I'm developing. 我正在使用PHPUnit尝试对一些PHP文件进行单元测试,这些文件是我正在开发的Web应用程序的一部分。 I've got a WAMP server set up, and have set my php.ini file to have the curl extension installed. 我已经设置了WAMP服务器,并设置了我的php.ini文件以安装curl扩展。 I've verified it's installed by checking phpinfo(), and curl does have a config section on the page, indicating it's installed. 我已经通过检查phpinfo()验证了它已安装,并且curl在页面上有一个配置部分,表明它已安装。

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. 当我从索引页面开始运行我的整个Web应用程序时,我正在尝试测试的这个php页面找到curl_init()函数没有问题。

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. 就像我说的那样,调用curl_init()的文件在整个应用程序的上下文中运行时效果很好,但是当我的PHPUnit测试单独运行它时却无法找到它。 Does anyone know why this is happening? 有谁知道为什么会这样? Does PHPUnit not know how to find the PHP extensions installed on my WAMP server? PHPUnit不知道如何找到我的WAMP服务器上安装的PHP扩展吗?

You need to add the Curl libraries to the command line PHP.ini. 您需要将Curl库添加到命令行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). 您可以将文件C:\\wamp\\bin\\apache\\Apache2.2.x\\bin\\php.ini复制到c:\\wamp\\bin\\php\\php5.3.10\\php.ini (调整实际目录在你的系统上)。

Open your c:\\wamp\\bin\\php\\php5.xx\\php.ini file and find: 打开你的c:\\wamp\\bin\\php\\php5.xx\\php.ini文件,找到:

    ;extension=php_curl.dll

Just uncomment it by removing the semicolon, such as: 只需删除分号即可取消注释,例如:

    extension=php_curl.dll

and save the file. 并保存文件。

The latest php.ini file will have 最新的php.ini文件将有

;extension=curl ;延长=卷曲

so please remove ; 所以请删除; and save works fine 并保存工作正常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM