PHP查找对象扩展的所有实例

时间:2018-06-27 23:27:14

标签: php introspection object-oriented-analysis

在PHP中-我有一堆测试,这些测试由“ testCase”对象扩展。

我不想维护所有测试的数组,所以我只想了解如何获取由“ testCase”扩展的对象的所有实例的数组。

有什么想法吗?

这是我的testCase对象

class testCase {

  public $testName;
  public $methodNames;
  public $methodCount;

  public $failiures;
  public $passes;

  public function __construct() {
   $this->testName = get_class($this);
   $this->methodNames = get_class_methods($this);
   $this->methodCount = count($this->methodNames);

   $this->failures = array();
   $this->passes = array();

   $this->setupTests();
   $this->runTests();
   $this->tearDown();
 }


 public function setupTests() {

 }

 public function runTests() {

  foreach ($this->methodNames as $method) {

  $skippableMethods = array(
    '__construct',
    'setupTests',
    'runTests',
    'tearDown',
    'displayResults',
    'getPassedTests',
    'getFailedTests'
  );

  if (in_array($method, $skippableMethods)) {
    continue;
  }

  if ($this->$method() === true) {
    $this->passes[] = $method;
  } else {
    $this->failures[] = $method;
  }

}

}

public function tearDown() {

}

public function getPassedTests() {
  return $this->passes;
}

public function getFailedTests() {
  return $this->failures;
}

}

0 个答案:

没有答案