suite = new PHPUnit_Framework_TestSuite("{$name} unit test"); $this->collect(TESTS_DIR . DS . str_replace('::', DS, $name)); } /** * Collects all test from the directory and it sub directories * * @param string $dname directory name */ private function collect($dname){ foreach(new DirectoryIterator($dname) as $file){ if ($file == '.' || $file == '..') { continue; } if ($file->isDir()){ $this->collect($file->getRealPath()); } else if (preg_match('/Test\.php$/', $file)) { require_once $file->getRealPath(); $this->suite->addTestSuite(str_replace('.php', '', $file)); } else if ($file == 'setup.php'){ require_once $file->getRealPath(); } } } /** * Run the tests * * @param array $arguments arguments, options, for the PHPUnit::TestRunner */ public function run($arguments = array()){ try { echo '
'; $runner = new PHPUnit_TextUI_TestRunner(); $result = $runner->doRun($this->suite, $arguments); echo ''; } catch (Exception $e) { throw new RuntimeException("Could not create and run test suite: {$e->getMessage()}"); } if ($result->wasSuccessful()){ exit(PHPUnit_TextUI_TestRunner::SUCCESS_EXIT); } else if($result->errorCount() > 0){ exit(PHPUnit_TextUI_TestRunner::EXCEPTION_EXIT); } else { exit(PHPUnit_TextUI_TestRunner::FAILURE_EXIT); } } }