/** * Runs a suite of unit tests * * @param string $directory Directory with tests. * @param string $suffix Test file suffix. * @throws \Exception When invalid test found. * @return boolean */ public function run($directory, $suffix) { $this->resultPrinter->suiteHeader($this, $directory . '/*' . $suffix); $passed = true; $facade = new \File_Iterator_Facade(); $old_handler = set_error_handler(array($this, 'handlePHPErrors')); foreach ($facade->getFilesAsArray($directory, $suffix) as $path) { $test = (require $path); if (!$test instanceof xTest) { throw new \Exception("'{$path}' is not a valid unit test"); } $test->setResultPrinter($this->resultPrinter); $passed = $passed && $test->run($this); } if ($old_handler) { set_error_handler($old_handler); } else { restore_error_handler(); } $this->resultPrinter->createCodeCoverageReport($this->coverage); $this->resultPrinter->suiteFooter($this); return $passed; }