PageRenderTime 49ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/htdocs/solar/1.1.1/source/solar/Solar/Test/Suite/load-tests.php

http://github.com/pmjones/php-framework-benchmarks
PHP | 124 lines | 80 code | 22 blank | 22 comment | 22 complexity | e6e359c8f0435d8e105e7a9e9d9d777d MD5 | raw file
Possible License(s): LGPL-3.0, Apache-2.0, BSD-3-Clause, ISC, AGPL-3.0, LGPL-2.1
  1. <?php
  2. function __autoload($class) {
  3. $class_file = str_replace('_', DIRECTORY_SEPARATOR, $class) . ".php";
  4. include_once $class_file;
  5. }
  6. function solar_load_test_files($dir)
  7. {
  8. $list = glob($dir . DIRECTORY_SEPARATOR . "[A-Z]*.php");
  9. foreach ($list as $class_file) {
  10. include_once $class_file;
  11. }
  12. $list = glob($dir . DIRECTORY_SEPARATOR . "[A-Z]*", GLOB_ONLYDIR);
  13. foreach ($list as $sub) {
  14. solar_load_test_files($sub);
  15. }
  16. }
  17. // report all errors
  18. error_reporting(E_ALL|E_STRICT);
  19. // look in this directory for tests
  20. $dir = rtrim($_SERVER['argv'][1], DIRECTORY_SEPARATOR);
  21. // starting with this class
  22. $class = $_SERVER['argv'][2];
  23. if (! $class) {
  24. $class = null;
  25. }
  26. // method prefix?
  27. $method = $_SERVER['argv'][3];
  28. if (! $method) {
  29. $method = null;
  30. }
  31. // "only" the class and/or method?
  32. $only = (bool) $_SERVER['argv'][4];
  33. // find the top-level file for the class
  34. $class_file = $dir
  35. . DIRECTORY_SEPARATOR
  36. . str_replace('_', DIRECTORY_SEPARATOR, $class)
  37. . ".php";
  38. if (file_exists($class_file) && is_readable($class_file)) {
  39. require_once $class_file;
  40. }
  41. // load all test files under the class dir, if it's not the only one to test
  42. if (! $only) {
  43. $subdir = substr($class_file, 0, -4);
  44. solar_load_test_files($subdir);
  45. }
  46. // now that all the files are loaded, let's see what classes we found
  47. $test_classes = get_declared_classes();
  48. sort($test_classes);
  49. $data = array('plan' => 0, 'tests' => array());
  50. $count = 0;
  51. foreach ($test_classes as $test_class) {
  52. // is it a Test_* class?
  53. if (substr($test_class, 0, 5) != 'Test_') {
  54. continue;
  55. }
  56. // ignore abstracts and interfaces
  57. $reflect = new ReflectionClass($test_class);
  58. if ($reflect->isAbstract() || $reflect->isInterface()) {
  59. continue;
  60. }
  61. // is it an "only" class?
  62. if ($only && $test_class != $class) {
  63. continue;
  64. }
  65. // find all the test*() methods in the Test_* class
  66. $test_methods = get_class_methods($test_class);
  67. foreach ($test_methods as $test_method) {
  68. // skip non test*() methods
  69. if (substr($test_method, 0, 4) != 'test') {
  70. continue;
  71. }
  72. // are we looking for only one method to test?
  73. if ($only && $method) {
  74. // match only the one exact method
  75. if ($method != $test_method) {
  76. continue;
  77. }
  78. // add only this one method to the plan, and break out
  79. $data['plan'] ++;
  80. $data['tests'][$test_class][] = $test_method;
  81. break;
  82. }
  83. // not looking for only one method
  84. if ($method) {
  85. // look for a matching prefix
  86. $prefix = substr($test_method, 0, strlen($method));
  87. if ($method == $prefix) {
  88. // add the test class and method to the plan
  89. $data['plan'] ++;
  90. $data['tests'][$test_class][] = $test_method;
  91. }
  92. } else {
  93. // not looking for a prefix, add the method
  94. $data['plan'] ++;
  95. $data['tests'][$test_class][] = $test_method;
  96. }
  97. }
  98. }
  99. // dump the serialized data
  100. echo serialize($data) . PHP_EOL;
  101. // exit code 104 is "EXIT_PASS"
  102. exit(104);