예제 #1
0
 /**
  * Executes the tests depending on our settings
  *
  * @return void
  * @access private
  */
 public function __run()
 {
     $Reporter = new CakeXmlReporter('utf-8', array('app' => $this->Manager->appTest, 'plugin' => $this->Manager->pluginTest, 'group' => $this->type === 'group', 'codeCoverage' => $this->doCoverage));
     if ($this->doCoverage) {
         if (!extension_loaded('xdebug')) {
             $this->out(__('You must install Xdebug to use the CakePHP(tm) Code Coverage Analyzation. Download it from http://www.xdebug.org/docs/install', true));
             $this->_stop(0);
         }
     }
     ob_start();
     try {
         if ($this->type == 'all') {
             $result = $this->Manager->runAllTests($Reporter);
         } else {
             if ($this->type == 'group') {
                 $ucFirstGroup = ucfirst($this->file);
                 if ($this->doCoverage) {
                     require_once CAKE . 'tests' . DS . 'lib' . DS . 'code_coverage_manager.php';
                     CodeCoverageManager::init($ucFirstGroup, $Reporter);
                     CodeCoverageManager::start();
                 }
                 $result = $this->Manager->runGroupTest($ucFirstGroup, $Reporter);
             } else {
                 $folder = $folder = $this->__findFolderByCategory($this->category);
                 $case = $this->__getFileName($folder, $this->isPluginTest);
                 if ($this->doCoverage) {
                     require_once CAKE . 'tests' . DS . 'lib' . DS . 'code_coverage_manager.php';
                     CodeCoverageManager::init($case, $Reporter);
                     CodeCoverageManager::start();
                 }
                 $result = $this->Manager->runTestCase($case, $Reporter);
             }
         }
     } catch (Exception $e) {
         ob_get_clean();
         $this->out('Tests failed to run. ' . $e->getMessage());
         $this->_stop(1);
     }
     $xml = ob_get_clean();
     $xmlD = new DOMDocument();
     $xmlD->loadXML($xml);
     $xslt = new XSLTProcessor();
     $XSL = new DOMDocument();
     $XSL->load(dirname(__FILE__) . DS . 'xsl' . DS . 'to-junit.xsl');
     $xslt->importStylesheet($XSL);
     $out = $xslt->transformToXML($xmlD);
     $time = time();
     file_put_contents(ROOT . DS . "build" . DS . "logs" . DS . "junit-{$time}.xml", $out);
     echo "Done.\n";
 }
예제 #2
0
 /**
  * Paints the end of the test with a summary of
  * the passes and failures.
  *
  * @param string $test_name Name class of test.
  * @return void
  * @access public
  */
 function paintFooter($test_name)
 {
     if ($this->getFailCount() + $this->getExceptionCount() == 0) {
         echo "OK\n";
     } else {
         echo "FAILURES!!!\n";
     }
     echo "Test cases run: " . $this->getTestCaseProgress() . "/" . $this->getTestCaseCount() . ", Passes: " . $this->getPassCount() . ", Failures: " . $this->getFailCount() . ", Exceptions: " . $this->getExceptionCount() . "\n";
     echo 'Time taken by tests (in seconds): ' . $this->_timeDuration . "\n";
     if (function_exists('memory_get_peak_usage')) {
         echo 'Peak memory use: (in bytes): ' . number_format(memory_get_peak_usage()) . "\n";
     }
     if (isset($this->params['codeCoverage']) && $this->params['codeCoverage'] && class_exists('CodeCoverageManager')) {
         CodeCoverageManager::report();
     }
 }
 /**
  * testCalculateCodeCoverage method
  *
  * @access public
  * @return void
  */
 function testCalculateCodeCoverage()
 {
     $manager =& CodeCoverageManager::getInstance();
     $data = array('25' => array(100, 25), '50' => array(100, 50), '0' => array(0, 0), '0' => array(100, 0), '100' => array(100, 100));
     foreach ($data as $coverage => $lines) {
         $this->assertEqual($coverage, $manager->__calcCoverage($lines[0], $lines[1]));
     }
     $manager->__calcCoverage(100, 1000);
     $this->assertError();
 }
예제 #4
0
 /**
  * Paints the end of the test with a summary of
  * the passes and failures.
  *
  * @param string $test_name Name class of test.
  * @return void
  * @access public
  */
 function paintFooter($test_name)
 {
     $colour = $this->getFailCount() + $this->getExceptionCount() > 0 ? "red" : "green";
     echo "</ul>\n";
     echo "<div style=\"";
     echo "padding: 8px; margin: 1em 0; background-color: {$colour}; color: white;";
     echo "\">";
     echo $this->getTestCaseProgress() . "/" . $this->getTestCaseCount();
     echo " test cases complete:\n";
     echo "<strong>" . $this->getPassCount() . "</strong> passes, ";
     echo "<strong>" . $this->getFailCount() . "</strong> fails and ";
     echo "<strong>" . $this->getExceptionCount() . "</strong> exceptions.";
     echo "</div>\n";
     echo '<div style="padding:0 0 5px;">';
     echo '<p><strong>Time taken by tests (in seconds):</strong> ' . $this->_timeDuration . '</p>';
     if (function_exists('memory_get_peak_usage')) {
         echo '<p><strong>Peak memory use: (in bytes):</strong> ' . number_format(memory_get_peak_usage()) . '</p>';
     }
     echo $this->_paintLinks();
     echo '</div>';
     if (isset($this->params['codeCoverage']) && $this->params['codeCoverage'] && class_exists('CodeCoverageManager')) {
         CodeCoverageManager::report();
     }
     $this->paintDocumentEnd();
 }
예제 #5
0
 /**
  * Paint a footer with test case name, timestamp, counts of fails and exceptions.
  */
 function paintFooter($test_name)
 {
     $buffer = $this->getTestCaseProgress() . '/' . $this->getTestCaseCount() . ' test cases complete: ';
     if (0 < $this->getFailCount() + $this->getExceptionCount()) {
         $buffer .= $this->getPassCount() . " passes";
         if (0 < $this->getFailCount()) {
             $buffer .= ", " . $this->getFailCount() . " fails";
         }
         if (0 < $this->getExceptionCount()) {
             $buffer .= ", " . $this->getExceptionCount() . " exceptions";
         }
         $buffer .= ".\n";
         $buffer .= $this->_timeStats();
         fwrite(STDOUT, $buffer);
     } else {
         fwrite(STDOUT, $buffer . $this->getPassCount() . " passes.\n" . $this->_timeStats());
     }
     if (isset($this->params['codeCoverage']) && $this->params['codeCoverage'] && class_exists('CodeCoverageManager')) {
         CodeCoverageManager::report();
     }
 }
예제 #6
0
    if ('all' == $_GET['group']) {
        TestManager::runAllTests(CakeTestsGetReporter());
    } else {
        if ($analyzeCodeCoverage) {
            CodeCoverageManager::start($_GET['group'], CakeTestsGetReporter());
        }
        TestManager::runGroupTest(ucfirst($_GET['group']), CakeTestsGetReporter());
        if ($analyzeCodeCoverage) {
            CodeCoverageManager::report();
        }
    }
    CakePHPTestRunMore();
    CakePHPTestAnalyzeCodeCoverage();
} elseif (isset($_GET['case'])) {
    if ($analyzeCodeCoverage) {
        CodeCoverageManager::start($_GET['case'], CakeTestsGetReporter());
    }
    TestManager::runTestCase($_GET['case'], CakeTestsGetReporter());
    if ($analyzeCodeCoverage) {
        CodeCoverageManager::report();
    }
    CakePHPTestRunMore();
    CakePHPTestAnalyzeCodeCoverage();
} elseif (isset($_GET['show']) && $_GET['show'] == 'cases') {
    CakePHPTestCaseList();
} else {
    CakePHPTestGroupTestList();
}
CakePHPTestSuiteFooter();
$output = ob_get_clean();
echo $output;
 /**
  * Runs a test case file.
  *
  * @return void
  */
 function _runTestCase()
 {
     $Reporter =& CakeTestSuiteDispatcher::getReporter();
     if ($this->params['codeCoverage']) {
         CodeCoverageManager::init($this->params['case'], $Reporter);
     }
     $this->Manager->runTestCase($this->params['case'], $Reporter);
 }
 /**
  * Gets us the base path to look for the test files
  *
  * @param string $isApp
  * @return void
  * @access public
  */
 function __getTestFilesPath($isApp = true)
 {
     $manager = CodeCoverageManager::getInstance();
     $path = ROOT . DS;
     if ($isApp) {
         $path .= APP_DIR . DS;
     } elseif (!!$manager->pluginTest) {
         $pluginPath = APP . 'plugins' . DS . $manager->pluginTest . DS;
         $pluginPaths = Configure::read('pluginPaths');
         foreach ($pluginPaths as $tmpPath) {
             $tmpPath = $tmpPath . $manager->pluginTest . DS;
             if (file_exists($tmpPath)) {
                 $pluginPath = $tmpPath;
                 break;
             }
         }
         $path = $pluginPath;
     } else {
         $path = TEST_CAKE_CORE_INCLUDE_PATH;
     }
     return $path;
 }
 /**
  * Paints the end of a test method being run.  This is used
  * to pause the collection of code coverage if its being used.
  *
  * @param string $method The name of the method being run.
  * @return void
  */
 function paintMethodEnd($method)
 {
     parent::paintMethodEnd($method);
     if (!empty($this->params['codeCoverage'])) {
         CodeCoverageManager::stop();
     }
 }
예제 #10
0
 /**
  * Executes the tests depending on our settings
  *
  * @return void
  * @access private
  */
 function __run()
 {
     $reporter = new CLIReporter();
     $this->__setGetVars();
     if ($this->type == 'all') {
         return TestManager::runAllTests($reporter);
     }
     if ($this->doCoverage) {
         if (!extension_loaded('xdebug')) {
             $this->out('You must install Xdebug to use the CakePHP(tm) Code Coverage Analyzation. Download it from http://www.xdebug.org/docs/install');
             exit(0);
         }
     }
     if ($this->type == 'group') {
         $ucFirstGroup = ucfirst($this->file);
         $path = CORE_TEST_GROUPS;
         if ($this->category == 'app') {
             $path = APP_TEST_GROUPS;
         } elseif ($this->isPluginTest) {
             $path = APP . 'plugins' . DS . $this->category . DS . 'tests' . DS . 'groups';
         }
         if ($this->doCoverage) {
             require_once CAKE . 'tests' . DS . 'lib' . DS . 'code_coverage_manager.php';
             CodeCoverageManager::start($ucFirstGroup, $reporter);
         }
         $result = TestManager::runGroupTest($ucFirstGroup, $reporter);
         if ($this->doCoverage) {
             CodeCoverageManager::report();
         }
         return $result;
     }
     $case = 'libs' . DS . $this->file . '.test.php';
     if ($this->category == 'app') {
         $case = $this->file . '.test.php';
     } elseif ($this->isPluginTest) {
         $case = $this->file . '.test.php';
     }
     if ($this->doCoverage) {
         require_once CAKE . 'tests' . DS . 'lib' . DS . 'code_coverage_manager.php';
         CodeCoverageManager::start($case, $reporter);
     }
     $result = TestManager::runTestCase($case, $reporter);
     if ($this->doCoverage) {
         CodeCoverageManager::report();
     }
     return $result;
 }
예제 #11
0
파일: testsuite.php 프로젝트: asairoha/pj01
 /**
  * Executes the tests depending on our settings
  *
  * @return void
  * @access private
  */
 function __run()
 {
     $Reporter = new CakeCliReporter('utf-8', array('app' => $this->Manager->appTest, 'plugin' => $this->Manager->pluginTest, 'group' => $this->type === 'group', 'codeCoverage' => $this->doCoverage));
     if ($this->type == 'all') {
         return $this->Manager->runAllTests($Reporter);
     }
     if ($this->doCoverage) {
         if (!extension_loaded('xdebug')) {
             $this->out(__('You must install Xdebug to use the CakePHP(tm) Code Coverage Analyzation. Download it from http://www.xdebug.org/docs/install', true));
             $this->_stop(0);
         }
     }
     if ($this->type == 'group') {
         $ucFirstGroup = ucfirst($this->file);
         if ($this->doCoverage) {
             require_once CAKE . 'tests' . DS . 'lib' . DS . 'code_coverage_manager.php';
             CodeCoverageManager::init($ucFirstGroup, $Reporter);
             CodeCoverageManager::start();
         }
         $result = $this->Manager->runGroupTest($ucFirstGroup, $Reporter);
         return $result;
     }
     $folder = $folder = $this->__findFolderByCategory($this->category);
     $case = $this->__getFileName($folder, $this->isPluginTest);
     if ($this->doCoverage) {
         require_once CAKE . 'tests' . DS . 'lib' . DS . 'code_coverage_manager.php';
         CodeCoverageManager::init($case, $Reporter);
         CodeCoverageManager::start();
     }
     $result = $this->Manager->runTestCase($case, $Reporter);
     return $result;
 }
예제 #12
0
 /**
  * Gets us the base path to look for the test files
  *
  * @param string $isApp
  * @return void
  * @access public
  */
 function __getTestFilesPath($isApp = true)
 {
     $manager = CodeCoverageManager::getInstance();
     $path = ROOT . DS;
     if ($isApp) {
         $path .= APP_DIR . DS;
     } elseif (!!$manager->pluginTest) {
         $path .= APP_DIR . DS . 'plugins' . DS . $manager->pluginTest . DS;
     } else {
         $path = TEST_CAKE_CORE_INCLUDE_PATH;
     }
     return $path;
 }