PageRenderTime 56ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/bin/ethna_run_test.php

http://github.com/ethna/ethna
PHP | 181 lines | 164 code | 3 blank | 14 comment | 7 complexity | 5049e861f674933e8ebc1777f359f121 MD5 | raw file
Possible License(s): BSD-3-Clause
  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. /** Ethna??????????????? */
  13. define('ETHNA_INSTALL_BASE', dirname(dirname(__FILE__)));
  14. $symlink_filename = null;
  15. /** ??????????????????????????? */
  16. /** symlink ??? 5.3.0 ???? Windows ??????? */
  17. /** ??Cygwin?????????????? */
  18. if (basename(ETHNA_INSTALL_BASE) != 'Ethna') {
  19. $symlink_filename = dirname(ETHNA_INSTALL_BASE) . "/Ethna";
  20. if (!file_exists($symlink_filename)) {
  21. symlink(ETHNA_INSTALL_BASE, $symlink_filename);
  22. } else {
  23. if (!is_link($symlink_filename)
  24. || realpath($symlink_filename) != ETHNA_INSTALL_BASE) {
  25. echo "Base dir 'Ethna' exists and it's not ETHNA_INSTALL_BASE.\n";
  26. exit(1);
  27. }
  28. else {
  29. // ???????? symlink ??????
  30. $symlink_filename = null;
  31. }
  32. }
  33. }
  34. /** ??????????????? */
  35. $test_dir = ETHNA_INSTALL_BASE . '/test';
  36. /** include_path???(??test runner????????????) */
  37. //ini_set('include_path', realpath(ETHNA_INSTALL_BASE . '/class') . PATH_SEPARATOR . ini_get('include_path'));
  38. ini_set('include_path', realpath(dirname(ETHNA_INSTALL_BASE)) . PATH_SEPARATOR . ini_get('include_path'));
  39. /** Ethna???????????? */
  40. require_once 'Ethna/Ethna.php';
  41. // simpletest ?????????E_DEPRECATED, E_STRICT ???
  42. error_reporting(error_reporting() & ~E_DEPRECATED & ~E_STRICT);
  43. if (extension_loaded('xdebug')) {
  44. ini_set('xdebug.scream', 0);
  45. }
  46. /** SimpleTest??????? */
  47. require_once 'simpletest/unit_tester.php';
  48. require_once 'simpletest/reporter.php';
  49. require_once $test_dir . '/TextSimpleReporter.php';
  50. require_once $test_dir . '/TextDetailReporter.php';
  51. require_once $test_dir . '/UnitTestBase.php';
  52. $test = new TestSuite('Ethna All tests');
  53. // ?????????????????
  54. require_once 'Ethna/class/Getopt.php';
  55. $opt = new Ethna_Getopt();
  56. $args = $opt->readPHPArgv();
  57. array_shift($args);
  58. $opt_ret = $opt->getopt($args, "", array('coverage', 'verbose'));
  59. if (Ethna::isError($opt_ret)) {
  60. echo $opt_ret->getMessage(), PHP_EOL;
  61. exit(255);
  62. }
  63. list($args, $opts) = $opt_ret;
  64. $coverage = false;
  65. $verbose = false;
  66. foreach ($args as $arg) {
  67. switch ($arg[0]) {
  68. case '--coverage':
  69. $coverage = true;
  70. break;
  71. case '--verbose':
  72. $verbose = true;
  73. break;
  74. }
  75. }
  76. if (count($opts) > 0) {
  77. $file_list = $opts;
  78. } else {
  79. $file_list = getFileList($test_dir);
  80. }
  81. // ?????????
  82. foreach ($file_list as $file) {
  83. $test->addFile($file);
  84. }
  85. if ($coverage) {
  86. // ?????????
  87. require_once 'PHP/CodeCoverage.php';
  88. $base = dirname(dirname(__FILE__));
  89. $filter = PHP_CodeCoverage_Filter::getInstance();
  90. $filter->addDirectoryToBlacklist($base.'/test');
  91. $filter->addDirectoryToBlacklist($base . '/src');
  92. $filter->addDirectoryToBlacklist($base . '/bin');
  93. $filter->addFileToBlacklist(__FILE__);
  94. require_once 'PEAR/Config.php';
  95. $pear_config = PEAR_Config::singleton();
  96. $pear_dir = $pear_config->get('php_dir');
  97. $filter->addDirectoryToBlacklist($pear_dir);
  98. $code_coverage = new PHP_CodeCoverage();
  99. $code_coverage->start('ethna');
  100. }
  101. // ?????????????
  102. if ($verbose) {
  103. $test->run(new TextDetailReporter());
  104. } else {
  105. $test->run(new TextSimpleReporter());
  106. }
  107. if ($symlink_filename !== null && is_link($symlink_filename)) {
  108. unlink($symlink_filename);
  109. }
  110. if ($coverage) {
  111. // ?????????
  112. $code_coverage->stop();
  113. require 'PHP/CodeCoverage/Report/HTML.php';
  114. $writer = new PHP_CodeCoverage_Report_HTML();
  115. $writer->process($code_coverage, getcwd().'/coverage');
  116. }
  117. //{{{ getFileList
  118. /**
  119. * getFileList
  120. *
  121. * @param string $dir_path
  122. */
  123. function getFileList($dir_path)
  124. {
  125. $file_list = array();
  126. $dir = opendir($dir_path);
  127. if ($dir == false) {
  128. return false;
  129. }
  130. while($file_path = readdir($dir)) {
  131. $full_path = $dir_path . '/'. $file_path;
  132. if (is_file($full_path)){
  133. // ?????????????????
  134. if (preg_match('/^(.*)(_Test.php)$/',$file_path,$matches)) {
  135. $file_list[] = $full_path;
  136. }
  137. // ????????????????????????
  138. // "."?????????????????.
  139. } else if (is_dir($full_path) && !preg_match('/^\./',$file_path,$matches)) {
  140. $file_list = array_merge($file_list,getFileList($full_path));
  141. }
  142. }
  143. closedir($dir);
  144. return $file_list;
  145. }
  146. //}}}