/** * */ function doTesting() { $dirHandle = opendir(Ruth::getREAL_PATH() . "/" . $this->testDir); set_time_limit(0); $wd_host = 'http://localhost:4444/wd/hub'; $this->message("Initialize testing on " . $wd_host . " for " . $this->testServer); $this->message("Test Path: " . Ruth::getREAL_PATH() . "/" . $this->testDir); $this->message("Loading test methods into class"); //include all the files , append all the functions / methods $fileArray = []; $i = 0; while (false !== ($entry = readdir($dirHandle))) { if ($entry != "." && $entry != ".." && stripos($entry, ".php")) { $fileArray[$i] = Ruth::getREAL_PATH() . "/" . $this->testDir . "/" . $entry; $i++; } } asort($fileArray); $functions = get_defined_functions(); $arrayFunctions = array_keys($functions['user']); $last_index = array_pop($arrayFunctions); // Include your file here. foreach ($fileArray as $fid => $fileName) { require_once $fileName; } $functions = get_defined_functions(); $new_functions = array_slice($functions['user'], $last_index); unset($new_functions[0]); foreach ($new_functions as $fid => $functionName) { $arguments = $this->get_func_argNames($functionName); $temp = ""; foreach ($arguments as $aid => $argument) { $temp[] = '$' . $argument; } if (!empty($temp)) { $arguments = implode($temp, ','); } else { $arguments = ""; } eval('$this->methods["' . $functionName . '"] = \\Closure::bind(function(' . $arguments . ') { ' . $functionName . '(' . $arguments . '); }, $this, get_class());'); } $this->message("Test Functions added: " . print_r(implode($new_functions, ","), 1)); $web_driver = new PHPWebDriver_WebDriver($wd_host); if (!empty(Ruth::getSESSION("tessaSession"))) { $this->session = unserialize(Ruth::getSESSION("tessaSession")); } else { $browser_profile = new PHPWebDriver_WebDriverFirefoxProfile(dirname(dirname(__FILE__)) . "/selenium/firefox-profile"); $this->session = $web_driver->session($this->browser, array(), array(), $browser_profile); Ruth::setSESSION("tessaSession", serialize($this->session)); } //this is the default port for testing try { $this->session->open($this->testServer); } catch (Exception $e) { $browser_profile = new PHPWebDriver_WebDriverFirefoxProfile(dirname(dirname(__FILE__)) . "/selenium/firefox-profile"); $this->session = $web_driver->session($this->browser, array(), array(), $browser_profile); Ruth::setSESSION("tessaSession", serialize($this->session)); $this->session->open($this->testServer); } $this->session->window()->maximize(); //go through each test, load then up and run them echo "<pre>"; echo "<h1>Running Tests!</h1>"; $this->runTests(); echo "</pre>"; }
/** * Do Migration * * Do Migration finds the last possible migration based on what is read from the database on the constructor * It then opens the migration file, imports it into the database and tries to run each statement. * The migration files must run in sequence and Maggy will stop if she hits an error! * * DO NOT USE COMMIT STATEMENTS IN YOUR MIGRATIONS , RATHER BREAK THINGS UP INTO SMALLER LOGICAL PIECES */ function doMigration() { $dirHandle = opendir(Ruth::getREAL_PATH() . "/" . $this->migrationPath); $error = false; set_time_limit(0); echo "<pre>"; echo "STARTING Maggy ....\n"; $error = false; error_reporting(0); $fileArray = []; while (false !== ($entry = readdir($dirHandle)) && !$error) { if ($entry != "." && $entry != ".." && stripos($entry, ".sql")) { $fileParts = explode(".", $entry); $fileParts = explode(" ", $fileParts[0]); $fileArray[$fileParts[0]] = $entry; } } asort($fileArray); foreach ($fileArray as $fid => $entry) { $fileParts = explode(".", $entry); $fileParts = explode(" ", $fileParts[0]); $sqlCheck = "select * from tina4_maggy where migration_id = '{$fileParts[0]}'"; $record = $this->DEB->getRow($sqlCheck); $migrationId = $fileParts[0]; unset($fileParts[0]); $description = join(" ", $fileParts); $content = file_get_contents(Ruth::getREAL_PATH() . "/" . $this->migrationPath . "/" . $entry); $runsql = false; if (empty($record)) { echo "<span style=\"color:orange;\">RUNNING:\"{$migrationId} {$description}\" ...</span>\n"; $transId = $this->DEB->startTransaction(); $sqlInsert = "insert into tina4_maggy (migration_id, description, content, passed)\n values ('{$migrationId}', '{$description}', ?, 0)"; $this->DEB->exec($sqlInsert, $transId, $content); $this->DEB->commit($transId); $runsql = true; } else { if ($record->PASSED === "0" || $record->PASSED === "") { echo "<span style=\"color:orange;\">RETRY: \"{$migrationId} {$description}\" ... </span> \n"; $runsql = true; } else { if ($record->PASSED === "1" || $record->PASSED == 1) { echo "<span style=\"color:green;\">PASSED:\"{$migrationId} {$description}\"</span>\n"; $runsql = false; } } } if ($runsql) { $transId = $this->DEB->startTransaction(); //before exploding the content, see if it is a stored procedure, trigger or view. if (stripos($content, "create trigger") === false && stripos($content, "create procedure") === false && stripos($content, "create view") === false) { $content = explode($this->delim, $content); } else { $sql = $content; $content = []; $content[] = $sql; } $error = false; foreach ($content as $cid => $sql) { if (!empty(trim($sql))) { $success = $this->DEB->exec($sql, $transId); if (!$success) { echo "<span style=\"color:red;\">FAILED: \"{$migrationId} {$description}\"</span>\nQUERY:{$sql}\nERROR:" . $this->DEB->getError() . "\n"; $error = true; break; } else { echo "<span style=\"color:green;\">PASSED:</span> "; } echo $sql . " ...\n"; } } if ($error) { echo "<span style=\"color:red;\">FAILED: \"{$migrationId} {$description}\"</span>\nAll Transactions Rolled Back ...\n"; $this->DEB->rollbackTransaction($transId); } else { $this->DEB->commit($transId); //we need to make sure the commit resulted in no errors if ($this->DEB->getError() !== "No Error") { echo "<span style=\"color:red;\">FAILED COMMIT: \"{$migrationId} {$description}\"</span>\nERROR:" . $this->DEB->getError() . "\n"; $this->DEB->rollbackTransaction($transId); $error = true; break; } else { $transId = $this->DEB->startTransaction(); $this->DEB->exec("update tina4_maggy set passed = 1 where migration_id = '{$migrationId}'", $transId); $this->DEB->commit($transId); echo "<span style=\"color:green;\">PASSED: \"{$migrationId} {$description}\"</span>\n"; } } } } if (!$error) { echo "FINISHED!"; } error_reporting(E_ALL); echo "</pre>"; }