
Mac OS X LionでPHPUnitとXdebugを使用してコードのカバー率を確認する方法です。
環境
Mac OS X 10.7.3
PHP 5.3.9
PHPUnit 3.6.10
Xdebug 2.1.2
PHP 5.3.9
PHPUnit 3.6.10
Xdebug 2.1.2
1.Xdebugのインストール
$ sudo port install php5-xdebug
インストールされたか確認します。
$ php -i | grep -i "xdebug support" xdebug support => enabled
2.レポートの生成
Xdebugがインストールされると、PHPUnitの–coverage-htmlオプションが使用可能になります。$ phpunit --coverage-html ./report ExampleTest
PHPUnit 3.6.10 by Sebastian Bergmann.
.....
Time: 0 seconds, Memory: 5.75Mb
OK (5 tests, 12 assertions)
Generating code coverage report, this may take a moment.
これで、カレントディレクトリにreportディレクトリと関連ファイルが生成されました。report/index.htmlをブラウザで表示して確認してみましょう。
- http://localhost/report/

できました。
参考