在cakephp中使用 phpunit


这个问题折腾一点时间,所以吸取教训,先上一个流程图

1.安装pear
1)在命令行中,进入php安装目录,运行:

go-pear.bat

(可能出现报错情况)
2)下载go-phar.bat至php安装目录,运行:

php go-pear.phar

3)双击刚产生的PEAR_ENV.reg ,导入注册表
4)此时pear应该安装成功了,更新至最新版本:

pear upgrade

(这一步挺重要的,phpunit貌似是使用pear的1.9.x才能安装)

这部分参考了http://blog.csdn.net/calllmq/article/details/7865057

2、安装phpunit

这部分需要注意一些东西,上面文章链接中的方法在cakephp 中不适用,按照官方手册的写法

pear upgrade PEAR
pear config-set auto_discover 1
pear install pear.phpunit.de/PHPUnit-3.7.32

使用pear 安装3.7版本,cakephp手册提示


PHPUnit 4 is not compatible with CakePHP’s Unit Testing.

Depending on your system’s configuration, you may need to run the previous commands withsudo

Once PHPUnit is installed with the PEAR installer, you should confirm that the PHPUnit libraries are on PHP’sinclude_path. You can do this by checking your php.ini file and making sure that the PHPUnit files are in one of theinclude_pathdirectories.

所以不能安装4.0版本,并且需要添加include_path,我之前添加include_path 还是失败,主要是路径的原因

先说下include_path 作用是简化requre 的时候找到路径

引用一段博文

在php.ini文件中可以设置成

 

include_path = ".;C:/xampp/xampp/php/PEAR"
include_path = ".;C:/Aptana Studio Workspace/jsms"

 

这样我们可以在程序当中不写路径可以直接include或者require进来jsms或者PEAR文件夹下面的php文件.

 

php代码如下

 

require_once('jsms_conf.php');  // jsms_conf.php 文件在 C:/Aptana Studio Workspace/jsms/下面

因为cakephp 包含的的是 PHPUnit/Autoload.php

所以include_path必须在phpunit的上一级目录下即可,例如我的PHPunit目录C:\wamp\bin\php\php5.4.3\pear\PHPUnit 那么设置include_path include_path = ".;C:\wamp\bin\php\php5.4.3\pear"就可以了

成功之后就是这样子

优质内容筛选与推荐>>
1、20175223 姚明宇 MyCP
2、Marquee相关
3、怎样理解阻塞非阻塞与同步异步的区别?
4、noip2009 潜伏者
5、百万并发之 tcp_mem


长按二维码向我转账

受苹果公司新规定影响,微信 iOS 版的赞赏功能被关闭,可通过二维码转账支持公众号。

    阅读
    好看
    已推荐到看一看
    你的朋友可以在“发现”-“看一看”看到你认为好看的文章。
    已取消,“好看”想法已同步删除
    已推荐到看一看 和朋友分享想法
    最多200字,当前共 发送

    已发送

    朋友将在看一看看到

    确定
    分享你的想法...
    取消

    分享想法到看一看

    确定
    最多200字,当前共

    发送中

    网络异常,请稍后重试

    微信扫一扫
    关注该公众号