Exemple #1
0
 /**
  * Runs all tests.
  * @param  string  path
  * @return void
  */
 public function run()
 {
     $number = $failed = $passed = 0;
     if (is_file($this->path)) {
         $files = array($this->path);
     } else {
         $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->path));
     }
     foreach ($files as $entry) {
         $info = pathinfo($entry);
         if (!isset($info['extension']) || $info['extension'] !== 'phpt') {
             continue;
         }
         $number++;
         $testCase = new NetteTestCase($entry, $this->cmdLine);
         try {
             echo $testCase->getName(), ': ';
             $testCase->run();
             $passed++;
             echo "OK";
         } catch (NetteTestCaseException $e) {
             echo $e->getMessage();
             $failed++;
             if ($testCase->getExpectedOutput() !== NULL) {
                 $this->log($entry, $testCase->getOutput(), self::OUTPUT);
                 $this->log($entry, $testCase->getExpectedOutput(), self::EXPECTED);
             }
             if ($testCase->getExpectedHeaders() !== NULL) {
                 $this->log($entry, $testCase->getHeaders(), self::OUTPUT, self::HEADERS);
                 $this->log($entry, $testCase->getExpectedHeaders(), self::EXPECTED, self::HEADERS);
             }
         }
         echo "\n";
     }
     echo "\nTest result summary\n-------------------\n";
     echo "Number of tests: {$number}\n";
     echo "Tests failed: {$failed}\n";
     echo "Tests passed: {$passed}\n";
     echo "-------------------\n";
 }
Exemple #2
0
 /**
  * Runs all tests.
  * @return void
  */
 public function run()
 {
     $count = 0;
     $failed = $passed = $skipped = array();
     if (is_file($this->path)) {
         $files = array($this->path);
     } else {
         $files = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->path));
     }
     foreach ($files as $entry) {
         $entry = (string) $entry;
         $info = pathinfo($entry);
         if (!isset($info['extension']) || $info['extension'] !== 'phpt') {
             continue;
         }
         $count++;
         $testCase = new NetteTestCase($entry);
         $testCase->setPhp($this->phpBinary, $this->phpArgs, $this->phpEnvironment);
         try {
             $testCase->run();
             echo '.';
             $passed[] = array($testCase->getName(), $entry);
         } catch (NetteTestCaseException $e) {
             if ($e->getCode() === NetteTestCaseException::SKIPPED) {
                 echo 's';
                 $skipped[] = array($testCase->getName(), $entry, $e->getMessage());
             } else {
                 echo 'F';
                 $failed[] = array($testCase->getName(), $entry, $e->getMessage());
                 $this->log($entry, $testCase->getOutput(), self::OUTPUT);
                 $this->log($entry, $testCase->getExpectedOutput(), self::EXPECTED);
                 if ($testCase->getExpectedHeaders() !== NULL) {
                     $this->log($entry, $testCase->getHeaders(), self::OUTPUT, self::HEADERS);
                     $this->log($entry, $testCase->getExpectedHeaders(), self::EXPECTED, self::HEADERS);
                 }
             }
         }
     }
     $failedCount = count($failed);
     $skippedCount = count($skipped);
     if ($this->displaySkipped && $skippedCount) {
         echo "\n\nSkipped:\n";
         foreach ($skipped as $i => $item) {
             list($name, $file, $message) = $item;
             echo "\n", $i + 1, ") {$name}\n   {$message}\n   {$file}\n";
         }
     }
     if (!$count) {
         echo "No tests found\n";
     } elseif ($failedCount) {
         echo "\n\nFailures:\n";
         foreach ($failed as $i => $item) {
             list($name, $file, $message) = $item;
             echo "\n", $i + 1, ") {$name}\n   {$message}\n   {$file}\n";
         }
         echo "\nFAILURES! ({$count} tests, {$failedCount} failures, {$skippedCount} skipped)\n";
         return FALSE;
     } else {
         echo "\n\nOK ({$count} tests, {$skippedCount} skipped)\n";
     }
     return TRUE;
 }