设为首页 收藏本站
查看: 1131|回复: 0

[经验分享] 在Windows下安装pear之后安装PHPUnit

[复制链接]

尚未签到

发表于 2016-5-24 10:41:17 | 显示全部楼层 |阅读模式
Windows 下安装pear,修改php5.x.x目录下的go-pear.bat如下:
 
 
@ECHO OFF
set PHP_BIN=php.exe
%PHP_BIN% -d phar.require_hash=0 PEAR\go-pear.phar
pause
 
 
以下内容于2012-09-07更新
 
步骤:
 
到 http://windows.php.net/downloads/releases/archives/ 下载PHP,解压并重命名到为php5.x.x,进入C:\Program Files\PHP5.x.x目录
如果需要扩展,打开php.ini,设置 extension_dir = "ext" , 取消对应扩展的注释
打开cmd,进入C:\Program Files\PHP5.x.x目录,运行go-pear
提示
Are you installing a system-wide PEAR or a local copy? (system|local) [system]
按回车确定
 
提示

    1. Installation base ($prefix)                  : D:\path_to_your_php\php5.x.x

   2. Temporary directory forprocessing            : D:\path_to_your_php\php5.x.x\tmp  

   3. Temporary directory fordownloads             : D:\path_to_your_php\php5.x.x\tmp  

   4. Binaries directory                           : D:\path_to_your_php\php5.x.x

   5. PHP code directory ($php_dir)                : D:\path_to_your_php\php5.x.x\pear  

   6. Documentation directory                      : D:\path_to_your_php\php5.x.x\docs  

   7. Data directory                               : D:\path_to_your_php\php5.x.x\data  

   8. User-modifiable configuration filesdirectory : D:\path_to_your_php\php5.x.x\cfg  

   9. Public Web Filesdirectory                    : D:\path_to_your_php\php5.x.x\www 

   10. Tests directory                             : D:\path_to_your_php\php5.x.x\tests 

   11. Name of configuration file                  : D:\path_to_your_php\php5.x.x\pear.ini 

   12. Pathto CLI php.exe                          : D:\path_to_your_php\php5.x.x 1-12, ‘all’ or Enter to continue:

 
确定无误,则按回车,输入数字则修改对应项。修改后,按回车进行安装。
 
生成环境变量PEAR_ENV.reg文件,双击导入注册表
此时,输入pear -V 查看版本信息,输入pear list 查看已安装的包
如果pear list查看没有 Image_GraphViz 包和 Log 包,则使用 pear install Log 安装Log,使用 pear install Image_GraphViz
安装 Image_GraphViz 时,如果提示不能包含Structures/Graph/Node.php,则
尝试set查看PHP_PEAR_*相关环境变量是否正确
尝试关闭cmd窗口,再打开,再pear install Image_GraphViz
尝试pear install Stuctures_Graph,再pear install Image_GraphViz
至此,pear list 应有

INSTALLED PACKAGES, CHANNEL PEAR.PHP.NET:
=========================================
PACKAGE          VERSION STATE
Archive_Tar      1.3.3   stable
Console_Getopt   1.2.3   stable
Image_GraphViz   1.3.0   stable
Log              1.12.7  stable
PEAR             1.9.0   stable
Structures_Graph 1.0.2   stable
XML_Util         1.2.1   stable 
 此时,使用 pear upgrade-all 即可升级所有的包。
 
 
如果安装成功在php5的安装目录下面会有一个pear.bat文件,这样就可以继续安装PHPUnit了。
 
  pear channel-discover pear.phpunit.de
  pear install phpunit/PHPUnit
 
运行上面命令后,会自动安装PHPUnit,安装完毕后在PHP5的安装目录下会有phpunit.bat这个文件,这样你就有了phpunit的命令行工具,在默认情况下PHP5的安装目录会自动加入到PATH环境变量中。
 
此时应发现 php 目录下,有phpunit,phpunit.bat两个文件,PEAR目录下有PHPUnit目录。
 
使用 phpunit --version 有 PHPUnit 3.6.12 by Sebastian Bergmann. 输出,说明安装成功。
 
安装完闭之后你的php.ini里面应该有include_path=".;C:\Program Files\PHP5.x.x\PEAR"这一行(注意重起apache让配置生效).
 
否则以后你require_once 'PHPUnit/Framework.php'的时候会引用不到.
 
修改 C:\Program Files\PHP5.x.x\phpunit.bat里的PHPBIN路径为php.exe(C:\Program Files\PHP5.x.x\php.exe)绝对地址,然后拷贝一个到C:\WINDOWS\system32目录下,这样可以直接用cmd命令运行了,打开dos窗口,转到你的代码目录下,然后运行phpunit 命令即可
 
到这里准备工作根本完成了,下面运行一个简单的Demo来检验一下效果:
 
编辑文件ArrayTest.php,放到PHP环境目录

<?php  
class ArrayTest extends PHPUnit_Framework_TestCase  
{  
public function testNewArrayIsEmpty()  
{  
// Create the Array fixture.  
$fixture = Array();  
// Assert that the size of the Array fixture is 0.  
$this->assertEquals(0, sizeof($fixture));  
}  
public function testArrayContainsAnElement()  
{  
// Create the Array fixture.  
$fixture = Array();  
// Add an element to the Array fixture.  
$fixture[] = 'Element';  
// Assert that the size of the Array fixture is 1.  
$this->assertEquals(1, sizeof($fixture));  
}  
}  
?>
 
然后在命令行下运行:phpunit ArrayTest,就可以看到相应的结果了。
 
不过在命令行下敲字母总是让人不爽的,我们可以让这个过程更有趣一些,以EditPlus编辑器为例:
Tools -> Configure User Tools -> Add Tool
然后设定:
Menu Text               : PHPUnit
Command               : C:\Program Files\PHP5.x.x\phpunit.bat
Argument                : $(FileNameNoExt)
InitialDirecotry         : $(FileDir)
搞定了,如果这是你的EditPlus中第一个UserTool的话,那么当你编辑好你的Test类文件后,只要按下Ctrl + 1就可以调出相应的命令行运行界面了。

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-221033-1-1.html 上篇帖子: windows下配置PHP+Nginx+MySQL完整流程 下篇帖子: Windows上用RubyMine4.0搭建Rails开发环境
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表