/** * Main function - runs the tests and outputs HTML code * * @return void * @author Robert Lemke <*****@*****.**> * @author Karsten Dambekalns <*****@*****.**> * @internal Preliminary solution - there surely will be nicer ways to implement a test runner */ public function run() { $this->renderPageHeader(); $this->renderTestForm(); if (!empty($this->packageKey)) { $testcaseFileNamesAndPaths = $this->getTestcaseFilenames(); if (count($testcaseFileNamesAndPaths) > 0) { $this->renderInfoAndProgressbar(); $this->requireTestCaseFiles($testcaseFileNamesAndPaths); $testListener = new \F3\Testing\TestListener(); $testListener->baseUri = $this->request->getBaseUri(); $testResult = new \PHPUnit_Framework_TestResult(); $testResult->addListener($testListener); $testResult->collectCodeCoverageInformation($this->collectCodeCoverage); $startTime = microtime(TRUE); foreach (get_declared_classes() as $className) { if (substr($className, -4, 4) == 'Test') { $class = new \ReflectionClass($className); if ($class->isSubclassOf('PHPUnit_Framework_TestCase') && substr($className, 0, 8) !== 'PHPUnit_') { $testSuite = new \PHPUnit_Framework_TestSuite($class); $testSuite->run($testResult); } } } $endTime = microtime(TRUE); // Display test statistics: if ($testResult->wasSuccessful()) { echo '<script type="text/javascript">document.getElementById("progress-bar").style.backgroundColor = "green";document.getElementById("progress-bar").style.backgroundImage = "none";</script> <h1 class="success">SUCCESS</h1> ' . $testResult->count() . ' tests, ' . $testResult->failureCount() . ' failures, ' . $testResult->errorCount() . ' errors. </h1>'; } else { echo ' <script>document.getElementById("progress-bar").style.backgroundColor = "red";document.getElementById("progress-bar").style.backgroundImage = "none";</script> <h1 class="failure">FAILURE</h1> ' . $testResult->count() . ' tests, ' . $testResult->failureCount() . ' failures, ' . $testResult->errorCount() . ' errors. '; } echo '<p>Peak memory usage was: ~' . floor(memory_get_peak_usage() / 1024 / 1024) . ' MByte.<br />'; echo 'Test run took ' . round($endTime - $startTime, 4) . ' seconds.</p>'; if ($this->collectCodeCoverage === TRUE) { \F3\FLOW3\Utility\Files::emptyDirectoryRecursively($this->coverageOutputPath); \PHPUnit_Util_Report::render($testResult, $this->coverageOutputPath); echo '<a href="_Resources/CodeCoverageReport/index.html">See code coverage report...</a>'; } } else { echo '<p>No testcase found. Did you specify the intended pattern?</p>'; } } $this->renderPageFooter(); }
/** * Removes all cache entries of this cache. * * @return void * @author Robert Lemke <*****@*****.**> * @api */ public function flush() { \F3\FLOW3\Utility\Files::emptyDirectoryRecursively($this->cacheDirectory); $this->systemLogger->log(sprintf('Cache %s: flushed all entries.', $this->cacheIdentifier), LOG_INFO); }