在cakephp中使用 phpunit

這個問題折騰一點時間,因此吸收教訓,先上一個流程圖php

 

1.安裝pear
1)在命令行中,進入php安裝目錄,運行:ui

go-pear.bat

(可能出現報錯狀況)
2)下載go-phar.bat至php安裝目錄,運行:this

php go-pear.phar

3)雙擊剛產生的PEAR_ENV.reg ,導入註冊表
4)此時pear應該安裝成功了,更新至最新版本:spa

pear upgrade

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

 

這部分參考了 http://blog.csdn.net/calllmq/article/details/7865057命令行

二、安裝phpunitblog

這部分須要注意一些東西,上面文章連接中的方法在cakephp 中不適用,按照官方手冊的寫法get

 

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.it

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

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_path directories.

 

因此不能安裝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"就能夠了

 

成功以後就是這樣子

相關文章
相關標籤/搜索