public function testImportBuilds() { $this->startCodeCoverage(); global $configure; $dir = $configure['svnroot']; chdir($dir); $argv[0] = 'importBuilds.php'; $xmlDirectory = dirname(__FILE__) . '/data/SubProjectExample'; $argv[1] = $xmlDirectory; $checkFile = dirname(__FILE__) . '/data/SubProjectExample/lastcheck'; if (file_exists($checkFile)) { cdash_testsuite_unlink($checkFile); } $argc = 1; ob_start(); include 'public/importBuilds.php'; $output = ob_get_contents(); ob_end_clean(); if (strpos($output, 'Usage: php') === false) { $this->fail("Expected output not found from importBuilds.php.\n{$output}\n"); return 1; } $argc = 2; ob_start(); include 'public/importBuilds.php'; $output = ob_get_contents(); ob_end_clean(); if (strpos($output, 'Import backup complete. 3 files processed.') === false) { $this->fail("Expected output not found from importBuilds.php.\n{$output}\n"); return 1; } ob_start(); include 'public/importBuilds.php'; $output = ob_get_contents(); ob_end_clean(); if (strpos($output, 'Import backup complete. 0 files processed.') === false) { $this->fail("Expected output not found from importBuilds.php.\n{$output}\n"); return 1; } $this->pass('Passed'); cdash_testsuite_unlink($checkFile); $this->deleteLog($this->logfilename); $this->stopCodeCoverage(); return 0; }
/** Delete the log file */ public function deleteLog($filename) { if (file_exists($filename)) { global $CDASH_TESTING_RENAME_LOGS; if ($CDASH_TESTING_RENAME_LOGS) { // Rename to a random name to keep for later inspection: // global $CDASH_LOG_DIRECTORY; rename($filename, $CDASH_LOG_DIRECTORY . '/cdash.' . microtime(true) . '.' . bin2hex(random_bytes(2)) . '.log'); } else { // Delete file: cdash_testsuite_unlink($filename); } } }
/** * configure the database for the test by droping the old * test database and creating a new one * @param object $reporter * @param array $db */ public function configure($reporter, $logfilename) { if (!$this->database) { echo "Please, set the database to the test manager before configure the test\n"; return false; } $reporter->paintConfigureStart(); $time_start = (double) array_sum(explode(' ', microtime())); $result = $this->_uninstalldb4test($this->database['host'], $this->database['port'], $this->database['login'], $this->database['pwd'], $this->database['name'], $this->database['type']); $time_end = (double) array_sum(explode(' ', microtime())); $execution_time = $time_end - $time_start; $time_start = $time_end; $reporter->paintConfigureUninstallResult($result); $result = $this->_connectToDb($this->database['host'], $this->database['port'], $this->database['login'], $this->database['pwd'], $this->database['name'], $this->database['type']); $reporter->paintConfigureConnection($result); if (file_exists($logfilename)) { // delete the log file -- result is success/failure $result = cdash_testsuite_unlink($logfilename); } else { // file is already not there -- equivalent to successfully deleting it $result = true; } $reporter->paintConfigureDeleteLogResult($result, $logfilename); $result = $this->_installdb4test($this->database['host'], $this->database['port'], $this->database['login'], $this->database['pwd'], $this->database['name'], $this->database['type']); $time_end = (double) array_sum(explode(' ', microtime())); $execution_time += $time_end - $time_start; $execution_time = round($execution_time / 60, 3); $reporter->paintConfigureInstallResult($result); $result = $this->_connectToDb($this->database['host'], $this->database['port'], $this->database['login'], $this->database['pwd'], $this->database['name'], $this->database['type']); $reporter->paintConfigureConnection($result); $reporter->paintConfigureEnd($execution_time); return $result; }
/** Delete the log file */ function deleteLog($filename) { if (file_exists($filename)) { global $CDASH_TESTING_RENAME_LOGS; if ($CDASH_TESTING_RENAME_LOGS) { // Rename to a random name to keep for later inspection: // global $CDASH_LOG_FILE; rename($filename, $CDASH_LOG_FILE . "." . mt_rand() . ".txt"); } else { // Delete file: cdash_testsuite_unlink($filename); } } }