尝试安装php-test_helpers以使用php5.4

现在必须安装一个名为php-test_helpers的东西。
这是从[PHP][PECL]test_helpers扩展模块引用的。

作为一个概念,它类似于一个扩展模块,用于在不能编写单元测试的遗留代码中轻松编写单元测试。总结一下其主要功能:

* 可以禁用exit/die函数,并指定回调函数
* 可以在执行new运算符时指定回调函数
* 可以重命名函数

貌似可以做到。
但是,在尝试使用phpenv安装PHP5.4.11时出现了错误,这是当时的记录。

环境

    • centos6.3(ゲストOS)

 

    macosx10.8(ホストOS)

所需的准备工作

    • php5.4以上

 

    git

可以使用以下网站作为参考

    • sebastianbergmann / php-test-helpers

 

    [PHP][PECL]test_helpers拡張モジュール

如果你不从git上拉取最新版本,会出现错误哦!!

从pecl的tgz文件下载后,使用make命令遇到了这个错误,让人苦恼不已。

$make


/bin/sh /tmp/test_helpers-1.0.0/libtool --mode=compile cc  -I. -I/tmp/test_helpers-1.0.0 -DPHP_ATOM_INC -I/tmp/test_helpers-1.0.0/include -I/tmp/test_helpers-1.0.0/main -I/tmp/test_helpers-1.0.0 -I/root/.phpenv/versions/5.4.11/include/php -I/root/.phpenv/versions/5.4.11/include/php/main -I/root/.phpenv/versions/5.4.11/include/php/TSRM -I/root/.phpenv/versions/5.4.11/include/php/Zend -I/root/.phpenv/versions/5.4.11/include/php/ext -I/root/.phpenv/versions/5.4.11/include/php/ext/date/lib  -DHAVE_CONFIG_H  -g -O2   -c /tmp/test_helpers-1.0.0/test_helpers.c -o test_helpers.lo 
mkdir .libs
 cc -I. -I/tmp/test_helpers-1.0.0 -DPHP_ATOM_INC -I/tmp/test_helpers-1.0.0/include -I/tmp/test_helpers-1.0.0/main -I/tmp/test_helpers-1.0.0 -I/root/.phpenv/versions/5.4.11/include/php -I/root/.phpenv/versions/5.4.11/include/php/main -I/root/.phpenv/versions/5.4.11/include/php/TSRM -I/root/.phpenv/versions/5.4.11/include/php/Zend -I/root/.phpenv/versions/5.4.11/include/php/ext -I/root/.phpenv/versions/5.4.11/include/php/ext/date/lib -DHAVE_CONFIG_H -g -O2 -c /tmp/test_helpers-1.0.0/test_helpers.c  -fPIC -DPIC -o .libs/test_helpers.o
/tmp/test_helpers-1.0.0/test_helpers.c: In function ‘new_handler’:
/tmp/test_helpers-1.0.0/test_helpers.c:87: error: ‘znode_op’ has no member named ‘u’

C不能读。。。。

Google for 2 hours. 请在 Google 上搜索 2 小时。

注意到有git存在!!

安装

cd /tmp
git clone https://github.com/sebastianbergmann/php-test-helpers.git
cd php-test-helpers
phpize
./configure
make
make test
make install 

设定

注意が必要ですが、Zend拡張が読み込まれているPHPの場合、それよりも下にモジュールをロードしないとエラーになると言われています。公式に書かれていましたが、気づかずに約20分間詰まりました。

 zend_extension="/root/.phpenv/versions/5.4.11/lib/php/extensions/no-debug-non-zts-20100525/xdebug.so"
 html_errors=on
# 下記を追加
 zend_extension=/root/.phpenv/versions/5.4.11/lib/php/extensions/no-debug-non-zts-20100525/test_helpers.so
~

请根据您自己的环境适时替换PATH等内容。由于我安装了phpenv,所以我将扩展模块放在了/root/.phpenv/versions/5.4.11/lib/php/extensions/no-debug-non-zts-20100525/目录下。只要指定php扩展模块的文件路径,就可以了。

我正在编辑xdebug.ini文件,但如果没有安装xdebug的话,我想新建一个应该也没有问题。

重新启动Nginx或Apache。

让我们重新启动web服务器。

重新启动php-fpm。

如果您使用php-fpm,请重新启动。

确认动作

我亲自试用一下。

<?php
set_exit_overload(function() { return FALSE; });
exit;
print 'We did not exit.';
unset_exit_overload();
exit;
print 'We exited and this will not be printed.';

如果显示的是”We did not exit”,则表示我们没有退出。

请注意,test_helpers已经迁移到了git,而pecl等已经过时了。我遇到了很多问题。。。。。

bannerAds