在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 with sudo

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"就可以了

成功之后就是这样子

时间: 2024-07-31 07:43:17

在cakephp中使用 phpunit的相关文章

cakephp中使用 find('count')方法

对于find('count',array('group'=>'user_id')); Model.php中这样描述: 1 /** 2 * Handles the before/after filter logic for find('count') operations. Only called by Model::find(). 3 * 4 * @param string $state Either "before" or "after" 5 * @para

在 CakePHP 中使用 SimpleExcel 遇到的一个问题小记

前言 以前在公司做的一个项目中遇到的一个问题,还有意思的. 问题 大家有没有在 CakePHP 中使用过第三方库?我现在在引入了一个名为 SimpleExcel 的第三方库时遇到了一些问题.我觉得问题可能跟我把这个库的库文件放在了不正确的目录下有关. 正常情况下,该库在解压后,会有一个名为 SimpleExcel 的目录,该目录下的文件结构如下: [email protected]:~/Desktop/faisalman-simple-excel-php-8d9fabc/src/SimpleEx

Cakephp中使用JavaScriptHelper来引入js文件

页面的head部分的内容在Cakephp中主要是有htmlhelper来进行控制的,而js部分则是由JavaScripthelper来进行控制的,在controller里面设置好:var $helpers = array(’Html’,'Javascript’);就可以在ctp文件中使用JavaScripthelper对象:$javascript了.具体见正文. 前提是js文件都放在了 webroot/js  目录下面了,下面是范例. 1.$javascript->link($JsName,0)

cakephp 中的in的用法

$this->Mymodel->find('all', array('conditions' => array('Mymodel.name' => array($authors ,$articles)),'order'=>'Mymodel.id DESC')); cakephp 中的in的用法

cakephp 中连接查询多表 或group by

$options = array( 'conditions' => $conditions, 'fields'=>array('Category.*','COUNT(`Entity`.`id`) as `entity_count`'), 'joins' => array('LEFT JOIN `entities` AS Entity ON `Entity`.`category_id` = `Category`.`id`'), 'group' => '`Category`.`id`'

CakePHP中出现persistent is not writable等Warning的解决方法

在新部署CakePHP项目或者从SVN中重新Update项目的时候,有时候会出现下面的警告: 这是因为app下tmp文件丢失的原因,tmp文件夹中存放的是系统生成的临时文件,在导出系统的时候一般会忽略.解决的办法就新建tmp及其子文件夹,tmp的文件夹结构如下:

cakephp中sql查询in

1.在httpd.conf开启LoadModule rewrite_module模块 2.让apache支持.htaccess,修改httpd.conf Options FollowSymLinks AllowOverride None 改为 Options FollowSymLinks AllowOverride All 原文地址:https://www.cnblogs.com/xiaobiaomei/p/9015778.html

PHPUnit 入门案例

了解PHPUnit 本案例是关于创建三角形的一个单元测试入门案例,在netbeans环境中完成,关于在此环境中搭建phpunit这里不再描述,可以参考以下资料完成搭建工作: http://www.cnblogs.com/x3d/p/phpunit-in-netbeans8.html https://phpunit.de/manual/current/zh_cn/installation.html https://github.com/sebastianbergmann/phpunit-skele

phpunit 入门

话说,使用phpunit还是处于好奇之心,为什么以前一直没使用呢?主要是嫌麻烦,小项目,前后端都是自己写,几个人就完成的工作,没必要弄的那么麻烦.好了,废话不多说,让我们一起来感受下phpunit吧! 假设,我们有一个项目Demo,Demo是使用Composer做的依赖管理.那么我们只需要以下几步就可完成phpunit的安装和使用: 一.phpunit安装: 1.下载phpunit:wget https://phar.phpunit.de/phpunit.phar 2.修改下载文件的权限:chm