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: d16562e7ebc3613271e9118a5894276b324b62c5 $
  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.         else {
  32.             // もとから存在した symlink は削除しない
  33.             $symlink_filename null;
  34.         }
  35.     }
  36. }
  37.  
  38. /** テストケースがあるディレクトリ */
  39. $test_dir ETHNA_INSTALL_BASE '/test';
  40.  
  41. /** include_pathの設定(このtest runnerがあるディレクトリを追加) */
  42. //ini_set('include_path', realpath(ETHNA_INSTALL_BASE . '/class') . PATH_SEPARATOR . ini_get('include_path'));
  43. ini_set('include_path'realpath(dirname(ETHNA_INSTALL_BASE)) PATH_SEPARATOR ini_get('include_path'));
  44.  
  45. /** Ethna関連クラスのインクルード */
  46. require_once 'Ethna/Ethna.php';
  47.  
  48. // simpletest を使っているため、E_DEPRECATED, E_STRICT は解除
  49. if (extension_loaded('xdebug')) {
  50.     ini_set('xdebug.scream'0);
  51. }
  52.  
  53. /** SimpleTestのインクルード */
  54. require_once 'simpletest/unit_tester.php';
  55. require_once 'simpletest/reporter.php';
  56. require_once $test_dir '/TextSimpleReporter.php';
  57. require_once $test_dir '/TextDetailReporter.php';
  58. require_once $test_dir '/UnitTestBase.php';
  59.  
  60. $test new TestSuite('Ethna All tests');
  61.  
  62. // テストケースのファイルリストを取得
  63. require_once 'Ethna/class/Getopt.php';
  64. $opt new Ethna_Getopt();
  65. $args $opt->readPHPArgv();
  66. array_shift($args);
  67. $opt_ret $opt->getopt($args""array('coverage''verbose'));
  68. if (Ethna::isError($opt_ret)) {
  69.     echo $opt_ret->getMessage()PHP_EOL;
  70.     exit(255);
  71. }
  72. list($args$opts$opt_ret;
  73.  
  74. $coverage false;
  75. $verbose false;
  76. foreach ($args as $arg{
  77.     switch ($arg[0]{
  78.     case '--coverage':
  79.         $coverage true;
  80.         break;
  81.  
  82.     case '--verbose':
  83.         $verbose true;
  84.         break;
  85.     }
  86. }
  87.  
  88. if (count($opts0{
  89.     $file_list $opts;
  90. else {
  91.     $file_list getFileList($test_dir);
  92. }
  93.  
  94. // テストケースを登録
  95. foreach ($file_list as $file{
  96.     $test->addFile($file);
  97. }
  98.  
  99. if ($coverage{
  100.     // カバレッジ計測開始
  101.     require_once 'PHP/CodeCoverage.php';
  102.  
  103.     $base dirname(dirname(__FILE__));
  104.  
  105.     $filter PHP_CodeCoverage_Filter::getInstance();
  106.     $filter->addDirectoryToBlacklist($base.'/test');
  107.     $filter->addDirectoryToBlacklist($base '/src');
  108.     $filter->addDirectoryToBlacklist($base '/bin');
  109.     $filter->addFileToBlacklist(__FILE__);
  110.  
  111.     require_once 'PEAR/Config.php';
  112.     $pear_config PEAR_Config::singleton();
  113.     $pear_dir $pear_config->get('php_dir');
  114.     $filter->addDirectoryToBlacklist($pear_dir);
  115.  
  116.     $code_coverage new PHP_CodeCoverage();
  117.     $code_coverage->start('ethna');
  118. }
  119.  
  120. // 結果をコマンドラインに出力
  121. if ($verbose{
  122.     $test->run(new TextDetailReporter());
  123. else {
  124.     $test->run(new TextSimpleReporter());
  125. }
  126.  
  127. if ($symlink_filename !== null && is_link($symlink_filename)) {
  128.     unlink($symlink_filename);
  129. }
  130.  
  131. if ($coverage{
  132.     // カバレッジ計測終了
  133.     $code_coverage->stop();
  134.  
  135.     require 'PHP/CodeCoverage/Report/HTML.php';
  136.     $writer new PHP_CodeCoverage_Report_HTML();
  137.     $writer->process($code_coveragegetcwd().'/coverage');
  138. }
  139.  
  140.  
  141. //{{{ getFileList
  142. /**
  143.  * getFileList
  144.  *
  145.  * @param string $dir_path 
  146.  */
  147. function getFileList($dir_path)
  148. {
  149.     $file_list array();
  150.  
  151.     $dir opendir($dir_path);
  152.  
  153.     if ($dir == false{
  154.         return false;
  155.     }
  156.  
  157.     while($file_path readdir($dir)) {
  158.  
  159.         $full_path $dir_path '/'$file_path;
  160.  
  161.         if (is_file($full_path)){
  162.  
  163.             // テストケースのファイルのみ読み込む
  164.             if (preg_match('/^(.*)(_Test.php)$/',$file_path,$matches)) {
  165.                 $file_list[$full_path;
  166.             }
  167.  
  168.         // サブディレクトリがある場合は,再帰的に読み込む.
  169.         // "."で始まるディレクトリは読み込まない.
  170.         else if (is_dir($full_path&& !preg_match('/^\./',$file_path,$matches)) {
  171.  
  172.             $file_list array_merge($file_list,getFileList($full_path));
  173.         }
  174.     }
  175.  
  176.     closedir($dir);
  177.     return $file_list;
  178. }
  179. //}}}

Documentation generated on Fri, 11 Nov 2011 03:58:06 +0900 by phpDocumentor 1.4.3