Пример #1
0
 /**
  * Searches for test files recursively in a given directory
  *
  * @param  string  $directory
  * @param  string  file $extension in the form of ".extname"
  * @return array   $test_files
  */
 public function findFiles($directory, $extension = null)
 {
     if (!empty($directory) && is_dir($directory)) {
         static $test_files = array();
         $opendir = opendir($directory) or agnosConsole::realTime("FATAL", "cannot open directory", $directory);
         $test_idx = 0;
         while (($name = readdir($opendir)) !== FALSE) {
             if (is_dir("{$directory}" . DIRECTORY_SEPARATOR . "{$name}") && !in_array($name, array('.', '..', 'CVS', '.svn'))) {
                 self::findFiles("{$directory}" . DIRECTORY_SEPARATOR . "{$name}");
             }
             /*
              * Get supported test file extensions
              */
             $config =& new CONFIGURATION();
             $extensions = $config->extensions;
             agnosConsole::message("Searching [ {$name} ]", true);
             foreach ($extensions as $ext) {
                 if (substr($name, -strlen($ext)) == $ext) {
                     $testfile = realpath("{$directory}" . DIRECTORY_SEPARATOR . "{$name}");
                     $test_files[] = $testfile;
                     $test_idx++;
                 }
             }
         }
         # end-while
         closedir($opendir);
         $test_files = array_unique($test_files);
         sort($test_files);
         return $test_files;
     }
     agnosConsole::realTime("FATAL", "Invalid directory", $directory);
     return false;
 }
Пример #2
0
 /**
  * Displays overall test summary
  *
  * @param  timestamp   Time tests started
  * @param  timestatmp  Time tests ended
  * @param  integer     Total number of tests found
  * @param  array       Array of failed tests
  */
 public function testSummary($_timeStart, $timeEnd, $totalTestCases, $failedTest)
 {
     $countFailed = sizeof($failedTest['FAILED']);
     $countSkipped = sizeof($failedTest['SKIPPED']);
     $countPassed = $totalTestCases - ($countFailed + $countSkipped);
     $avgTime = $timeEnd - $_timeStart;
     $timeStart = @date('Y-m-d H:i:s', $_timeStart);
     $timeEnd = @date('Y-m-d H:i:s', $timeEnd);
     $date = @date('D, Y-m-d H:i:s a', $_timeStart);
     $uniqid = @date('Y-m-d-H:i:s', $_timeStart);
     $filename = "agnos-report-{$uniqid}.txt";
     $testSummary = "\n                             TEST RESULT SUMMARY\n                       Copyright (C) 2008 agnos v0.0.1\n                       \nFilename    : {$filename}\nDate        : {$date}\n--------------------------------------------------------------------------------\nTotal Tests : {$totalTestCases}\nPassed      : {$countPassed}\nFailed      : {$countFailed}\nSkipped     : {$countSkipped}\n--------------------------------------------------------------------------------\n\nTIMESTAMP\n--------------------------------------------------------------------------------\nStarted     : {$timeStart}\nEnded       : {$timeEnd}\nTotal time  : {$avgTime} seconds\n--------------------------------------------------------------------------------\n";
     if ($countFailed >= 1) {
         $contents = agnosUtil::arrayToString($failedTest['FAILED'], 'name');
         $failedTestReport = "\nFAILED TESTS REPORT\n--------------------------------------------------------------------------------\n{$contents}\n--------------------------------------------------------------------------------\n";
         $testSummary .= $failedTestReport;
     }
     agnosConsole::message($testSummary);
     if (agnosFileDir::createDir('agnos-reports')) {
         agnosUtil::saveText('agnos-reports' . DIRECTORY_SEPARATOR . $filename, $testSummary);
     }
     return true;
 }
Пример #3
0
 /**
  * Runs all the test files
  *
  * @param   array   Test files
  * @return  boolean True/False
  * 
  * @access  public
  */
 public function testRunAll($Tests = null)
 {
     if (!is_null($Tests)) {
         if (is_array($Tests)) {
             /*
              * Set the test counter to 1 as the first test file being tested
              */
             $testId = 1;
             $timeStarted = agnosConsole::timeStart();
             $testCount = sizeof($Tests);
             /* show something in console */
             agnosConsole::message("\nTotal Test(s) Found : {$testCount}", false, true);
             foreach ($Tests as $testFile) {
                 /* Run the test file */
                 $this->testRun($testFile);
                 agnosConsole::testing($testId, $testCount, $testFile);
                 $testId++;
                 /* @todo : Temporarily clean-up */
                 @unlink($testFile . ".php");
                 @unlink($testFile . ".skip.php");
             }
         } else {
             $this->testRun($Tests);
         }
         /* Time end */
         $timeEnded = agnosConsole::timeEnd();
         /* Show test summary */
         agnosReporter::testSummary($timeStarted, $timeEnded, $testCount, $this->FailedTestTable);
     }
     return false;
 }