PHP上安装phpunit 及xdebug

WBOY
Libérer: 2016-06-13 11:00:37
original
787 Les gens l'ont consulté

PHP下安装phpunit 及xdebug

?? ? ? 话说之前在公司安装了下phpunit,测试了~~可是输出代码测试覆盖率,需要有php的扩展xdebug,就去网上找了这个xdebug?(<span style="color: #000000;">www.xdebug.org</span>),下载。
Copier après la connexion
?? ? ? 在公司的用的集成环境,下了一个5.2 Vc6(32bit)的,然修改名字为php_xdebug.dll ,然后按照教程说的配置php.ini文件如下:
Copier après la connexion
[Xdebug]
Copier après la connexion
Copier après la connexion
zend_extension_ts="c:/wamp/php/ext/php_xdebug.dll"
Copier après la connexion
xdebug.profiler_enable=on
Copier après la connexion
Copier après la connexion
xdebug.trace_output_dir="D:/PHPApp/xdebug"
Copier après la connexion
xdebug.profiler_output_dir="D:/PHPApp/xdebug"
Copier après la connexion
?
Copier après la connexion
可是发现,xdebug没有安装成功。
Copier après la connexion
按照教程的说法,xdebug这个扩展需要用zend的方式去加载,(至于原因大家网上查),可是就是不成功。
Copier après la connexion
今天早上起来一直想着这事,于是在自己的电脑上再次安装一次。
Copier après la connexion
也是先安装pear,特别一提,我的本子的环境是<span>独立安装</span>的,没有用集成。PHP的环境是5.2.10,
Copier après la connexion
在安装pear的时候还发生了一件小插曲:就是他运行这个命令加载到php的扩展php_exif这个扩展的时候报了一个错误,大致信息是我没有加载mbstring这个扩展,可是这个扩展我是已经加载成功了的,而且也能在phpinfo信息页看到,后来在javaeye上看到一个帖子,提到这个问题,原来exif这个扩展需要用到mbstring,可是在php.ini中加载的循序是按照字母来的,mbstring排在了exif扩展之后,所以导致加载到exif的时候找不到mbstring,解决方法也很简单,只要把mbstring的加载提到exif的前面就可以了。重启apache然后重新安装pear,即可。
Copier après la connexion
安装pear也是一样的方式安装?? go-pear,安装完成之后发现版本是1.7.1的,由于在公司安装的时候知道版本低,所以就进行了一次升级pear upgrade pear,升级到了1.9.1,然后再次安装PHPUnit,因为一直都说5的环境用的该是phpunit2而phpunit用的是4环境,于是安装
Copier après la connexion
pear channel-discover pear.phpunit.de???? OK后
Copier après la connexion
pear install --alldeps phpunit2
Copier après la connexion
完了后我运行phpunit,发现它的选项只有8个,而且版本是2.3.6:
Copier après la connexion
<img    style="max-width:90%" alt=""  style="max-width:90%" src="/img/2012/11/07/1228552541.jpg">
Copier après la connexion
觉得很奇怪,在公司安装的phpunit升级后版本是3。X的,难道我的安装有问题,于是我再次安装了一次phpunit,结果发现,我安装起来的phpunit竟然才是1.X?,太不可思议了,于是我删掉PHPunit,到了pear网站去看(<span style="color: #000000;">www.pear.php.net</span>),发现PHPunit2是2.3.6版本,于是我就卸载了phpunit,(pear uninstall phpunit),为了正确,我重新删除phpunit2重新安装,并且在安装前更新了下频道(pear update channels),然后再次安装phpunit2还是老样子,于是我就先隔着跑去安装xdebug,就是本文开篇说的那个方法再次安装。
Copier après la connexion
可是我发现在我的机子上我如果xdebug的安装模式的是zend的扩展模式,apache重启竟然出现错误。于是我改成用php的扩展方式开启,
Copier après la connexion

?

[Xdebug]
Copier après la connexion
Copier après la connexion
extension=php_xdebug.dll
Copier après la connexion
xdebug.profiler_enable=on
Copier après la connexion
Copier après la connexion
xdebug.trace_output_dir="E:/Alicx/php/xdebug"
Copier après la connexion
xdebug.profiler_output_dir="E:/Alicx/php/xdebug"
Copier après la connexion
重启成功,然后执行PHPinfo,看到了xdebug扩展项:
Copier après la connexion
<img alt="" src="/img/2012/11/07/1228552542.jpg">?
Copier après la connexion
然后我再次去命令行运行phpunit命令:
Copier après la connexion
<img alt="" src="/img/2012/11/07/1228552543.jpg">
Copier après la connexion
发现多了coverage这几个生成覆盖率文件的选项,而且开头提示我:xdebug必须以zend的扩展方式来加载,这可怎么办呢,于是我再次开启用zend的方式加载,然后重启apache,查看error日志发现:
Copier après la connexion
PHP Warning:? Xdebug MUST be loaded as a Zend extension in Unknown on line 0
Copier après la connexion
PHP Fatal error:? [Zend Optimizer] Zend Optimizer 3.3.3 is incompatible with Xdebug 2.1.0 in Unknown on line 0
Copier après la connexion
在javaeye找到这样一个帖子:
Copier après la connexion

<strong><strong><p style="display: inline !important;"><strong><span><strong><span style="font-size: small;"><span style="font-size: 12px;">xdebug 必须使用 zend_extension_ts 或者 zend_extension 来标明它是zend的扩展</span></span></strong></span></strong></p></strong></strong>
Copier après la connexion

根据 PHP 版本,zend_extension 指令可以是以下之一:
Copier après la connexion

zend_extension (non ZTS, non debug build)
Copier après la connexion

<span>zend_extension_ts ( ZTS, non debug build)</span>
Copier après la connexion

<strong><strong><span>zend_extension_debug (non ZTS, debug build)</span></strong></strong>
Copier après la connexion

<strong><span>zend_extension_debug_ts ( ZTS, debug build)</span></strong>
Copier après la connexion

<strong><strong><span>ZTS:ZEND Thread Safety</span></strong></strong>
Copier après la connexion

<strong><strong><span>可通过phpinfo()查看ZTS是否启用,从而决定用zend_extension还是zend_extension_ts。</span></strong></strong>
Copier après la connexion

<strong><strong>extension意为基于php引擎的扩展</strong></strong>
Copier après la connexion

<strong>zend_extension意为基于zend引擎的扩展</strong>
Copier après la connexion

问题就在这,我的php没有启用ZEND Thread Safety,所以不能采用zend_extension_ts这个的方式加载,改用zend_extension这个加载xdebug。
Copier après la connexion
重启apache,成功,再次运行phpunit:
Copier après la connexion
<img alt="" src="/img/2012/11/07/1228552544.jpg">
Copier après la connexion
<p><span style="color: #9900ff;">接下来是错误日志:</span></p><p><span style="color: #9900ff;">PHP Fatal error:? [Zend Optimizer] Zend Optimizer 3.3.3 is incompatible with Xdebug 2.1.0 in </span></p><p><span style="color: #9900ff;">Unknown on line 0</span></p><p><span style="color: #9900ff;">难道是我安装的zend optimizer有问题,?于是我把我的zend扩展全部打上注释,然后再次用xdebug的zend扩展</span></p><p><span style="color: #9900ff;">开启</span></p><p><img alt="" src="/img/2012/11/07/1228552545.jpg"></p><p><span   style="max-width:90%">终于有了那三个选项,查看phpinfo也有了xdebug选项</span></p><p><span style="color: #9900ff;">分析:看来xdebug和optimization有冲突吧,上网查找,果然被我发现一篇文章中提到,确实冲突了,</span></p><p><span style="color: #9900ff;">而且还找到zend_extension的扩展只有5.3才支持,所以还是得用zend_extension_ts来扩展xdebug</span></p><p><span style="color: #9900ff;">分享该文地址:</span><span style="color: #9900ff;">http://hi.baidu.com/fykknd/blog/item/e5734e5d3960b94efbf2c0a5.html</span></p>
Copier après la connexion
OK,可以用了····单元测试的覆盖率也有了,这里我就知道了,我的PHPunit2选项少时因为我没有安装其他的扩展导致单元测试的命令phpunit选项只有几个自己的,我装了xdebug之后,就有了覆盖率导出这些命令了~~~
Copier après la connexion
OK,自此完成安装!!,
Copier après la connexion
看来回公司我得好好看看我的xdebug的启动模式。
Copier après la connexion
                            ---本文同步发表在QQ空间:http://user.qzone.qq.com/414073277/blog/1292122868ps:  QQ空间图片竟然引用不过来······
Copier après la connexion

1 楼 逍遥虾 2010-12-13  
另外,今天早晨过来公司从同事口中才知道,PHPunit2是一个很老的版本了,目前的版本是phpunit 3.5  看来我落伍了··晚上回去升级去~~~

2 楼 caibaohua 2010-12-13  
装个ubuntu吧 apt-get 都能搞定
Étiquettes associées:
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal
À propos de nous Clause de non-responsabilité Sitemap
Site Web PHP chinois:Formation PHP en ligne sur le bien-être public,Aidez les apprenants PHP à grandir rapidement!