BlogPet

あわせて読みたい

あわせて読みたい

nakanohito

Firefox3 Meter

Yahoo! ログール

TwittPet

 

2008年 2月
« 1月   3月 »
 12
3456789
10111213141516
171819202122
242526272829  

検索

ページ

PHPUnitとPHPDocumentor

PHPのテストとドキュメント生成のメモ。

  1. PHPUnitをインストール
    # pear channel-discover pear.phpunit.de
    # pear install phpunit/PHPUnit
  2. PHPDocumentorをインストール
    # pear install --alldeps phpdocumentor
  3. 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″/>
  4. 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;
      }
    }
    ?>
  5. テストを生成(@assertの内容をテストコードに変換してくれる~^_^/)
    # phpunit --skeleton Hello
    PHPUnit 3.2.15 by Sebastian Bergmann.        
    
    Wrote test class skeleton for "Hello" to "HelloTest.php".      
    
    #
  6. テストを実行、確認
    # phpunit HelloTest
    PHPUnit 3.2.15 by Sebastian Bergmann.       
    
    ...       
    
    Time: 0 seconds       
    
    OK (3 tests)      
    
    #
  7. 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 are closed.

 |