Source for file ethna_run_test.php

Documentation is available at ethna_run_test.php

  1. <?php
  2. /**
  3.  *  ethna_run_test.php
  4.  *
  5.  *  Ethna Test Runner
  6.  *
  7.  *  @author     Kazuhiro Hosoi <hosoi@gree.co.jp>
  8.  *  @license    http://www.opensource.org/licenses/bsd-license.php The BSD License
  9.  *  @package    Ethna
  10.  *  @version    $Id$
  11.  */
  12.  
  13. /** Ethnaインストールルートディレクトリ */
  14. define('ETHNA_INSTALL_BASE'dirname(dirname(__FILE__)));
  15.  
  16. $symlink_filename null;
  17.  
  18. /** シンボリックリンクをインストールディレクトリの親に張る */
  19. /** symlink 関数は 5.3.0 以前では Windows 上で動作しない   */
  20. /** が、Cygwinでテストするため問題はない。                 */
  21. if (basename(ETHNA_INSTALL_BASE!= 'Ethna'{
  22.     $symlink_filename dirname(ETHNA_INSTALL_BASE"/Ethna";
  23.     if (!file_exists($symlink_filename)) {
  24.         symlink(ETHNA_INSTALL_BASE$symlink_filename);
  25.     else {
  26.         if (!is_link($symlink_filename)
  27.             || realpath($symlink_filename!= ETHNA_INSTALL_BASE{
  28.             echo "Base dir 'Ethna' exists and it's not ETHNA_INSTALL_BASE.\n";
  29.             exit(1);
  30.         }
  31.     }
  32. }
  33.  
  34. /** テストケースがあるディレクトリ */
  35. $test_dir ETHNA_INSTALL_BASE '/test';
  36.  
  37. /** include_pathの設定(このtest runnerがあるディレクトリを追加) */
  38. //ini_set('include_path', realpath(ETHNA_INSTALL_BASE . '/class') . PATH_SEPARATOR . ini_get('include_path'));
  39. ini_set('include_path'realpath(dirname(ETHNA_INSTALL_BASE)) PATH_SEPARATOR ini_get('include_path'));
  40.  
  41. /** Ethna関連クラスのインクルード */
  42. require_once 'Ethna/Ethna.php';
  43.  
  44. /** SimpleTestのインクルード */
  45. require_once 'simpletest/unit_tester.php';
  46. require_once 'simpletest/reporter.php';
  47. require_once $test_dir '/TextDetailReporter.php';
  48. require_once $test_dir '/Ethna_UnitTestBase.php';
  49.  
  50. $test &new GroupTest('Ethna All tests');
  51.  
  52. // テストケースのファイルリストを取得
  53. require_once 'Ethna/class/Ethna_Getopt.php';
  54. $opt new Ethna_Getopt();
  55. $args $opt->readPHPArgv();
  56. list($args$opts$opt->getopt($args''array());
  57. array_shift($opts);
  58. if (count($opts0{
  59.     $file_list $opts;
  60. else {
  61.     $file_list getFileList($test_dir);
  62. }
  63.  
  64. // テストケースを登録
  65. foreach ($file_list as $file{
  66.     $test->addTestFile($file);
  67. }
  68.  
  69. // 結果をコマンドラインに出力
  70. $test->run(new TextDetailReporter());
  71.  
  72. if ($symlink_filename !== null && is_link($symlink_filename)) {
  73.     unlink($symlink_filename);
  74. }
  75.  
  76. //{{{ getFileList
  77. /**
  78.  * getFileList
  79.  *
  80.  * @param string $dir_path 
  81.  */
  82. function getFileList($dir_path)
  83. {
  84.     $file_list array();
  85.  
  86.     $dir opendir($dir_path);
  87.  
  88.     if ($dir == false{
  89.         return false;
  90.     }
  91.  
  92.     while($file_path readdir($dir)) {
  93.  
  94.         $full_path $dir_path '/'$file_path;
  95.  
  96.         if (is_file($full_path)){
  97.  
  98.             // テストケースのファイルのみ読み込む
  99.             if (preg_match('/^(Ethna_)(.*)(_Test.php)$/',$file_path,$matches)) {
  100.                 $file_list[$full_path;
  101.             }
  102.  
  103.         // サブディレクトリがある場合は,再帰的に読み込む.
  104.         // "."で始まるディレクトリは読み込まない.
  105.         else if (is_dir($full_path&& !preg_match('/^\./',$file_path,$matches)) {
  106.  
  107.             $file_list array_merge($file_list,getFileList($full_path));
  108.         }
  109.     }
  110.  
  111.     closedir($dir);
  112.     return $file_list;
  113. }
  114. //}}}
  115.  
  116. ?>

Documentation generated on Fri, 11 Nov 2011 04:00:50 +0900 by phpDocumentor 1.4.3