PHPUnitとPHPDocumentor
PHPのテストとドキュメント生成のメモ。
- PHPUnitをインストール
# pear channel-discover pear.phpunit.de # pear install phpunit/PHPUnit
- PHPDocumentorをインストール
# pear install --alldeps phpdocumentor
- PHPDocumentorのheader.tplを修正(xml encodingとcharsetをUTF-8に)
<?xml version=“1.0″ encoding=“UTF-8″?>
<meta http-equiv=“Content-Type” content=“text/html; charset=UTF-8″/>
- Hello.phpを書く(@assertアノテーションを書いておく)
<?php /** @package default */ /** * Helloクラス * * 「Hello World」ファンクション * * @package default * @access public * @author satotech * @version $Id: hello,v 1.0 2008/02/23 23:50:00 satotech Exp $ */ class Hello { /** */ public function __construct() { } /** @assert () == null */ public function __destruct() { } /** * ‘こんにちは。’を返します * * @access public * @param String $name 名前 * @return String ‘$nameさん、こんにちは。’ or ‘こんにちは。’ * @assert () == ‘こんにちは。’ * @assert (’モモ’) == ‘モモさん、こんにちは。’ */ public function helloWorld($name=null) { $message = ‘こんにちは。’; return $name ? $name.‘さん、’.$message : $message; } } ?>
- テストを生成(@assertの内容をテストコードに変換してくれる~^_^/)
# phpunit --skeleton Hello PHPUnit 3.2.15 by Sebastian Bergmann. Wrote test class skeleton for "Hello" to "HelloTest.php". #
- テストを実行、確認
# phpunit HelloTest PHPUnit 3.2.15 by Sebastian Bergmann. ... Time: 0 seconds OK (3 tests) #
- PHPDocumentorでドキュメントを出力
# php phpdoc -d ./src -t ./doc ...(略)... done Parsing time: 0 seconds Conversion time: 3 seconds Total Documentation Time: 3 seconds done #
2008-2-23 23:50:25 by satotech
Posted in Programming | Comments Off