LoginSignup
4
4

More than 5 years have passed since last update.

php5.4でphp-test_helpersを入れてみる

Last updated at Posted at 2013-03-05

php-test_helpersなるものをいれなくては行けないことになった
[PHP][PECL]test_helpers拡張モジュールからの引用ですと

コンセプトとしては、ユニットテストを書けないようなレガシーコードで、ユニットテストを楽に書けるようにするための拡張モジュールのようで、ざっと機能をまとめてみると、

*exit/die関数の無効化やコールバックを指定できる
*newオペレータの実行時にコールバックを指定できる
*関数の改名

ができるらしい。
が、phpenvで入れたPHP5.4.11で入れようとしたらエラーになったのでその時のメモです

環境

  • centos6.3(ゲストOS)
  • macosx10.8(ホストOS)

事前準備に必要なもの

  • php5.4以上
  • git

参考にしたサイト

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は読めないって。。。。

ググること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_extensionがロードしているPHPの場合はそれより下にモジュールのロードをしないとエラーになるそうです。公式に書いてましたが気づかずに20分ほどハマりました。

/root/.phpenv/versions/5.4.11/etc/conf.d/xdebug.ini
 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 or apacheの再起動

webサーバーを再起動しましょう

php-fpmの再起動

php-fpmを使っているならば再起動しましょう

動作確認

実際に使ってみる

test_helper.php
<?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.';

exitをかけているがスルーしてWe did not exit.が表示されればOKです。

test_helpersがgitに移行されていてpeclとかは既に古くなってるのでご注意ください。これだいぶハマりました。。。。。

4
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
4