PHPunitをbakeしてみる

最近は、かくがくしかじかで、Zend Frameworkのお勉強をしておりますです。
2011年12月現在では、最新verは1.11.11ですが、上の本は1.7~8のお話です。
ver1.8以降劇的な修正は行われていないようなので、1.8系を学べばとりあえず問題なさそうです。

bash: phpunit: command not found

一通り参考書を読み終えたのですが、この本テストの仕方を書いてない。
というか、AirをもらってからPHPunit動かしてないぞ。
って思ったら、pearも入ってないぞって。

$ phpunit
bash: phpunit: command not found
$ pear
bash: pear: command not found

いれちゃお。

pear.php.netから落としてきたファイルを実行するよー!

$ curl http://pear.php.net/go-pear.phar> pear.php
$ sudo php -q pear.php

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) : /Users/******/pear
2. Temporary directory for processing : /tmp/pear/install
3. Temporary directory for downloads : /tmp/pear/install
4. Binaries directory : /Users/******/pear/bin
5. PHP code directory ($php_dir) : /Users/******/pear/share/pear
6. Documentation directory : /Users/******/pear/docs
7. Data directory : /Users/******/pear/data
8. User-modifiable configuration files directory : /Users/******/pear/cfg
9. Public Web Files directory : /Users/******/pear/www
10. Tests directory : /Users/******/pear/tests
11. Name of configuration file : /Users/******/.pearrc

1-11, 'all' or Enter to continue:

1を指定して、インストールパスを変更します!( /usr/share/pear にしました。)

1-11, 'all' or Enter to continue: 1
(Use $prefix as a shortcut for '/Users/******/pear', etc.)
Installation base ($prefix) [/Users/******/pear] : /usr/share/pear

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.

インストールパスを変更して、あとはOK!!ってやると、インストールが始まったみたい。
途中で、「php.ini変更しちゃっていい?」って聞かれたので、「Y(ご自由に〜。)」と言っておきました。

$ sudo ln -fs /usr/share/pear/bin/* /usr/bin/
$ pear list
Installed packages, channel pear.php.net:
=========================================
Package Version State
Archive_Tar 1.3.7 stable
Console_Getopt 1.3.0 stable
PEAR 1.9.4 stable
Structures_Graph 1.0.4 stable
XML_Util 1.2.1 stable

pearコマンドにパスが通っていないので、/usr/bin/以下にシンボリックリンクを張っておきますー。
にしても、リスト少ないなぁ。。

やっとこさPHPunitをいれる

PHPUnit – The PHP Testing Framework

$ pear config-set auto_discover 1
config-set succeeded

$ pear install pear.phpunit.de/PHPUnit
$ phpunit --version
PHPUnit 3.6.5 by Sebastian Bergmann.

おぉ出た出た、噂のセバスチャンベルグマン。
ここまで行けばおkかなぁ。
あとは、どんどんテストするだけーっと。

格言的な

ピアーじゃなくて、ペアーです。