Window下 PHPUnit的安装方法

准备做项目测试了,但是其实我并不知道怎么做测试,虽然之前有所准备,在看php面向对象的书。但还是云里雾里的,于是开在网上找各种资料安装phpunit 但是一般都是上来就是添加频道的命令,真是让人头疼,因为我根本不清楚那是什么意思。


概念:


“PHPUnit是一个轻量级的 PHP测试框架。它是在PHP5下面对JUnit3系列版本的完整移植,是xUnit测试框架家族的一员(它们都基于模式先锋Kent Beck的设计)。
单元测试是几个现代敏捷开发方法的基础,使得PHPUnit成为许多大型PHP项目的关键工具。这个工具也可以被Xdebug扩展用来生成代码覆盖率报告 ,并且可以与phing集成来自动测试,最后它还可以和Selenium整合来完成大型的自动化集成测试。”


其实这段我也不明白说什么呢。


在找资料的过程中我发现好多方法都是各种转载来的,能用不能用还两说真是让人头痛。索性我自己测试好了方上来。


我的环境
appserv 5.2.6 
框架 ci(CodeIgniter) 
zend studio 8.01


下面是zend 激活码 
zend studio 8 注册码(适用于7.0以上所有版本)
Username: zendstudio.net
Serial Number: 3727234F6095F72034F6095F


下面是我操作记录 可以看出来各种错误的地方。
关键代码 就两行 一个是安装,一个是注册,最后是添加频道的命令。
cmd 里

F:\>cd AppServ
 
F:\AppServ>dir
驱动器 F 中的卷是 WORKSTATION
卷的序列号是 C352-49C7
 
F:\AppServ 的目录
 
2012/11/24  20:15    <DIR>          .
2012/11/24  20:15    <DIR>          ..
2012/12/17  22:08    <DIR>          www
2012/11/24  20:15    <DIR>          Apache2.2
2012/11/24  20:15    <DIR>          php5
2012/11/24  20:15    <DIR>          MySQL
2012/11/24  20:15           119,214 Uninstall-AppServ2.5.10.exe
               1 个文件        119,214 字节
               6 个目录 200,772,681,728 可用字节



F:\AppServ\php5>go-pear.bat   //安装
F:\AppServ\php5>pear version PEAR Version: 1.9.4 PHP  //版本
Version: 5.2.6 Zend Engine Version: 2.2.0

F:\AppServ\php5>PEAR_ENV.reg  //注册

F:\AppServ\php5>pear channel-discover pear.phpunit.de //添加频道

Adding Channel "pear.phpunit.de" succeeded
Discovery of channel "pear.phpunit.de" succeeded

F:\AppServ\php5>pear channel-discover components.ez.no
Adding Channel "components.ez.no" succeeded
Discovery of channel "components.ez.no" succeeded
 
F:\AppServ\php5>pear channel-discover pear.symfony-project.com pear install phpu
nit/PHPUnit-3.5.5
No channel server specified
php pear安装
F:\>cd AppServ
 
F:\AppServ>dir
驱动器 F 中的卷是 WORKSTATION
卷的序列号是 C352-49C7 
F:\AppServ 的目录下的文件
www /Apache2.2 / php5 / MySQL/ Uninstall-AppServ2.5.10.exe
F:\AppServ>cd php5
 
F:\AppServ\php5>dir
驱动器 F 中的卷是 WORKSTATION
卷的序列号是 C352-49C7
 
F:\AppServ\php5 的目录
 
//主要执行的是这个文件
2013/01/14  15:53         3,681,106 go-pear.phar
 
/**
*这里是错误的操作,因为在pear文件夹里有一个文件以为用php去执行就可以了
*
***/
F:\AppServ\php5>php PEAR/go-pear.bat
Could not open input file: PEAR/go-pear.bat

//这句也是在网上看到的可能在其他环境下可以吧。
F:\AppServ\php5>php -d phar.require_hash=0 PEAR/go-pear.bat
Could not open input file: PEAR/go-pear.bat
 
F:\AppServ\php5> pear channel-discover pear.phpunit.de
'pear' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
 
F:\AppServ\php5>pear channel-discover pear.phpunit.de
'pear' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
 
F:\AppServ\php5>php -d phar.require_hash=0 PEAR/go-pear.bat
Could not open input file: PEAR/go-pear.bat
 
F:\AppServ\php5>php PEAR/go-pear.bat
Could not open input file: PEAR/go-pear.bat

/**这里是错误的操作***/

//这里是正确的
F:\AppServ\php5>go-pear.bat
 
Are you installing a system-wide PEAR or a local copy?
(system|local) [system] :
 
Below is a suggested file layout for your new PEAR installation.  To
change individual locations, type the number in front of the
directory.  Type 'all' to change all of them or simply press Enter to
accept these locations.
 
 1. Installation base ($prefix)                   : F:\AppServ\php5
 2. Temporary directory for processing            : F:\AppServ\php5\tmp
 3. Temporary directory for downloads             : F:\AppServ\php5\tmp
 4. Binaries directory                            : F:\AppServ\php5
 5. PHP code directory ($php_dir)                 : F:\AppServ\php5\pear
 6. Documentation directory                       : F:\AppServ\php5\docs
 7. Data directory                                : F:\AppServ\php5\data
8. User-modifiable configuration files directory : F:\AppServ\php5\cfg
 9. Public Web Files directory                    : F:\AppServ\php5\www
10. Tests directory                               : F:\AppServ\php5\tests
11. Name of configuration file                    : C:\Windows\pear.ini
12. Path to CLI php.exe                           : .
 
1-12, 'all' or Enter to continue:
 
*WARNING*
We found php.exe under ., it uses an unknown SAPI. PEAR commandline
tool has not been tested with it, if you have a CLI (or CGI) php.exe available,
we strongly recommend using it.
 
Beginning install...
Configuration written to C:\Windows\pear.ini...
Initialized registry...
Preparing to install...
installing phar://go-pear.phar/PEAR/go-pear-tarballs/Archive_Tar-1.3.7.tar...
installing phar://go-pear.phar/PEAR/go-pear-tarballs/Console_Getopt-1.3.0.tar...
 
installing phar://go-pear.phar/PEAR/go-pear-tarballs/PEAR-1.9.4.tar...
installing phar://go-pear.phar/PEAR/go-pear-tarballs/Structures_Graph-1.0.4.tar.
..
installing phar://go-pear.phar/PEAR/go-pear-tarballs/XML_Util-1.2.1.tar...
install ok: channel://pear.php.net/Archive_Tar-1.3.7
install ok: channel://pear.php.net/Console_Getopt-1.3.0
install ok: channel://pear.php.net/Structures_Graph-1.0.4
install ok: channel://pear.php.net/XML_Util-1.2.1
install ok: channel://pear.php.net/PEAR-1.9.4
PEAR: Optional feature webinstaller available (PEAR's web-based installer)
PEAR: Optional feature gtkinstaller available (PEAR's PHP-GTK-based installer)
PEAR: Optional feature gtk2installer available (PEAR's PHP-GTK2-based installer)
 
PEAR: To install optional features use "pear install pear/PEAR#featurename"
 
******************************************************************************
WARNING!  The include_path defined in the currently used php.ini does not
contain the PEAR PHP directory you just specified:
<F:\AppServ\php5\pear>
If the specified directory is also not in the include_path used by
your scripts, you will have problems getting any PEAR packages working.
 
 
Would you like to alter php.ini <C:\Windows\php.ini>? [Y/n] : y
 
php.ini <C:\Windows\php.ini> include_path updated.
 
Current include path           : .;C:\php5\pear
Configured directory           : F:\AppServ\php5\pear
Currently used php.ini (guess) : C:\Windows\php.ini
Press Enter to continue:
 
** WARNING! Old version found at F:\AppServ\php5, please remove it or be sure to
use the new f:\appserv\php5\pear.bat command
 
The 'pear' command is now at your service at f:\appserv\php5\pear.bat
 
 
* WINDOWS ENVIRONMENT VARIABLES *
For convenience, a REG file is available under F:\AppServ\php5PEAR_ENV.reg .
This file creates ENV variables for the current user.
 
Double-click this file to add it to the current user registry.
 
请按任意键继续. . .

//其实双击这个文件就可以了 
F:\AppServ\php5>pera_evn.reg
'pera_evn.reg' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
 
F:\AppServ\php5>pear version
PEAR Version: 1.9.4
PHP Version: 5.2.6
Zend Engine Version: 2.2.0
Running on: Windows NT CHAO 6.2 build 9200
 
F:\AppServ\php5>pear channel-discover pear.phpunit.de
Adding Channel "pear.phpunit.de" succeeded
Discovery of channel "pear.phpunit.de" succeeded
 
F:\AppServ\php5>pear channel-discover components.ez.no
Adding Channel "components.ez.no" succeeded
Discovery of channel "components.ez.no" succeeded
 
F:\AppServ\php5>pear channel-discover pear.symfony-project.com pear install phpu
nit/PHPUnit-3.5.5
No channel server specified
 
F:\AppServ\php5>
F:\AppServ\php5>pear version
PEAR Version: 1.9.4
PHP Version: 5.2.6
Zend Engine Version: 2.2.0
Running on: Windows NT CHAO 6.2 build 9200
 
F:\AppServ\php5>PEAR_ENV.reg
 
F:\AppServ\php5>pear channel-discover pear.symfony-project.com pear install phpu
nit/PHPUnit-3.5.5
No channel server specified
 
F:\AppServ\php5>pear channel-discover pear.phpunit.de
Channel "pear.phpunit.de" is already initialized
 
F:\AppServ\php5>
F:\AppServ\php5>pear channel-discover pear.symfony-project.com
Adding Channel "pear.symfony-project.com" succeeded
Discovery of channel "pear.symfony-project.com" succeeded
 
F:\AppServ\php5>pear install phpunit/PHPUnit
Did not download optional dependencies: pear/Image_GraphViz, pear/Log, symfony/Y
AML, use --alldeps to download automatically
phpunit/PHPUnit can optionally use package "pear/Image_GraphViz" (version >= 1.2
.1)
phpunit/PHPUnit can optionally use package "pear/Log"
phpunit/PHPUnit can optionally use package "symfony/YAML" (version >= 1.0.2)
phpunit/PHPUnit can optionally use PHP extension "xdebug" (version >= 2.0.5)
downloading PHPUnit-3.4.15.tgz ...
Starting to download PHPUnit-3.4.15.tgz (255,036 bytes)
.....................................................done: 255,036 bytes
install ok: channel://pear.phpunit.de/PHPUnit-3.4.15
 
F:\AppServ\php5>phpunit --version
PHPUnit 3.4.15 by Sebastian Bergmann.
  
其实简单的操作很简单,但是更多的都是直接添加频道。
 
然后就一直回车下去就可以了。但是还是会有问题,就是不能安装xdebug,因为版本低不已不支持zend引擎,不能够计算覆盖率。
 
上面可以看到我犯了好错误。不过打开文件可以看到一些有用的信息。 
 
go-pear.bat 里存储着 

@ECHO OFF
set PHP_BIN=php.exe
%PHP_BIN% -d output_buffering=0 PEAR\go-pear.phar
%PHP_BIN% -d phar.require_hash=0 PEAR\go-pear.phar
pause
好像是设置用哪个程序来处理go-pear.pahr的

据说会报错:

  “……~/Zend/ZendServer/bin/PEAR/go-pear.phar does not have a signature”

    通过查找资料,修改 go-pear.bat 的第三条语句

    %PHP_BIN% -d output_buffering=0 PEAR/go-pear.phar,为

    %PHP_BIN% -d phar.require_hash=0 PEAR/go-pear.phar

    才会开始安装 PEAR。

    修改后的 go-pear.bat 文件内容:

    @ECHO OFF
    set PHP_BIN=php.exe
    rem %PHP_BIN% -d output_buffering=0 PEAR/go-pear.phar
    %PHP_BIN% -d phar.require_hash=0 PEAR/go-pear.phar
    pause

不过最终我还是安装上了,基本能够使用。

我打算安装更高版本的进行测试。

我的这个也不很详细,也不仔细。(希望大家多多拍砖,谢谢!)下面是各家的参考,貌似不是复制粘贴的质量还可以,同时也是我学习的榜样。



http://be-evil.org/?keyword=unit&page=2
http://www.jb51.net/article/27194.htm
http://blog.csdn.net/zhangking/article/details/5712794
http://blog.lixiphp.com/windows-install-pear-phpunit/
http://www.jb51.net/article/27194.htm

小总结:

很多时候其实是自己不够耐心的学习观察才造成错误,同时不能够经常的反思和总结而经常犯同样的错误。

还有就是拿过就转用完就扔真不是什么好习惯。

这篇文章如果有时间我还会再次完善的。

你可能感兴趣的:(安装,单元测试,phpunit,Window8,appserv)