Windows下安装pear,修改php5.x.x目录下的go-pear.bat如下:
@ECHOOFF
setPHP_BIN=php.exe
%PHP_BIN%-dphar.require_hash=0PEAR\go-pear.phar
pause
以下内容于2012-09-07更新
步骤:
到http://windows.php.net/downloads/releases/archives/下载PHP,解压并重命名到为php5.x.x,进入C:\ProgramFiles\PHP5.x.x目录
如果需要扩展,打开php.ini,设置extension_dir="ext",取消对应扩展的注释
打开cmd,进入C:\ProgramFiles\PHP5.x.x目录,运行go-pear
提示
Areyouinstallingasystem-widePEARoralocalcopy?(system|local)[system]
按回车确定
提示
1.Installationbase($prefix):D:\path_to_your_php\php5.x.x
2.Temporarydirectoryforprocessing:D:\path_to_your_php\php5.x.x\tmp
3.Temporarydirectoryfordownloads:D:\path_to_your_php\php5.x.x\tmp
4.Binariesdirectory:D:\path_to_your_php\php5.x.x
5.PHPcodedirectory($php_dir):D:\path_to_your_php\php5.x.x\pear
6.Documentationdirectory:D:\path_to_your_php\php5.x.x\docs
7.Datadirectory:D:\path_to_your_php\php5.x.x\data
8.User-modifiableconfigurationfilesdirectory:D:\path_to_your_php\php5.x.x\cfg
9.PublicWebFilesdirectory:D:\path_to_your_php\php5.x.x\www
10.Testsdirectory:D:\path_to_your_php\php5.x.x\tests
11.Nameofconfigurationfile:D:\path_to_your_php\php5.x.x\pear.ini
12.PathtoCLIphp.exe:D:\path_to_your_php\php5.x.x1-12,‘all’orEntertocontinue:
确定无误,则按回车,输入数字则修改对应项。修改后,按回车进行安装。
生成环境变量PEAR_ENV.reg文件,双击导入注册表
此时,输入pear-V查看版本信息,输入pearlist查看已安装的包
如果pearlist查看没有Image_GraphViz包和Log包,则使用pearinstallLog安装Log,使用pearinstallImage_GraphViz
安装Image_GraphViz时,如果提示不能包含Structures/Graph/Node.php,则
尝试set查看PHP_PEAR_*相关环境变量是否正确
尝试关闭cmd窗口,再打开,再pearinstallImage_GraphViz
尝试pearinstallStuctures_Graph,再pearinstallImage_GraphViz
至此,pearlist应有
1
2
3
4
5
6
7
8
9
10
|
INSTALLEDPACKAGES,CHANNELPEAR.PHP.NET: ========================================= PACKAGEVERSIONSTATE Archive_Tar1.3.3stable Console_Getopt1.2.3stable Image_GraphViz1.3.0stable Log1.12.7stable PEAR1.9.0stable Structures_Graph1.0.2stable XML_Util1.2.1stable |
此时,使用pearupgrade-all即可升级所有的包。
如果安装成功在php5的安装目录下面会有一个pear.bat文件,这样就可以继续安装PHPUnit了。
pearchannel-discoverpear.phpunit.de
pearinstallphpunit/PHPUnit
运行上面命令后,会自动安装PHPUnit,安装完毕后在PHP5的安装目录下会有phpunit.bat这个文件,这样你就有了phpunit的命令行工具,在默认情况下PHP5的安装目录会自动加入到PATH环境变量中。
此时应发现php目录下,有phpunit,phpunit.bat两个文件,PEAR目录下有PHPUnit目录。
使用phpunit--version有PHPUnit3.6.12bySebastianBergmann.输出,说明安装成功。
安装完闭之后你的php.ini里面应该有include_path=".;C:\ProgramFiles\PHP5.x.x\PEAR"这一行(注意重起apache让配置生效).
否则以后你require_once'PHPUnit/Framework.php'的时候会引用不到.
修改C:\ProgramFiles\PHP5.x.x\phpunit.bat里的PHPBIN路径为php.exe(C:\ProgramFiles\PHP5.x.x\php.exe)绝对地址,然后拷贝一个到C:\WINDOWS\system32目录下,这样可以直接用cmd命令运行了,打开dos窗口,转到你的代码目录下,然后运行phpunit命令即可
到这里准备工作根本完成了,下面运行一个简单的Demo来检验一下效果:
编辑文件ArrayTest.php,放到PHP环境目录
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
<?php class ArrayTest extends PHPUnit_Framework_TestCase
{
public function testNewArrayIsEmpty()
{
//CreatetheArrayfixture.
$fixture =Array();
//AssertthatthesizeoftheArrayfixtureis0.
$this ->assertEquals(0,sizeof( $fixture ));
}
public function testArrayContainsAnElement()
{
//CreatetheArrayfixture.
$fixture =Array();
//AddanelementtotheArrayfixture.
$fixture []= 'Element' ;
//AssertthatthesizeoftheArrayfixtureis1.
$this ->assertEquals(1,sizeof( $fixture ));
}
} ?> |
然后在命令行下运行:phpunitArrayTest,就可以看到相应的结果了。
不过在命令行下敲字母总是让人不爽的,我们可以让这个过程更有趣一些,以EditPlus编辑器为例:
Tools->ConfigureUserTools->AddTool
然后设定:
MenuText:PHPUnit
Command:C:\ProgramFiles\PHP5.x.x\phpunit.bat
Argument:$(FileNameNoExt)
InitialDirecotry:$(FileDir)
搞定了,如果这是你的EditPlus中第一个UserTool的话,那么当你编辑好你的Test类文件后,只要按下Ctrl+1就可以调出相应的命令行运行界面了。