public function testCopyRecursive() { $this->guy->createTestFolderTree($this->tmpPath1); $this->assertTrue($this->guy->isTestFolderTree($this->tmpPath1)); FileSystemTools::copyRecursive($this->tmpPath1, $this->tmpPath2); $this->assertTrue($this->guy->isTestFolderTree($this->tmpPath2)); }
private function tryToTest(AcceptanceGuy $I) { // need a copy of test folder FileSystemTools::copyRecursive(TestConfig::getConfig('testPath'), $this->tmpStaging); $I->runShellCommand(TestConfig::getConfig('testRunnerPath') . DS . 'runtests.bat testStagingPath:' . $this->tmpStaging); $I->seeInShellOutput('Codeception PHP Testing Framework'); //$I->seeInShellOutput('PhantomJS server stopped'); }
function createTestTemplateFiles() { // prime from module template directories FileSystemTools::copyRecursive(getenv('thisTestRun_testRunnerPath') . '/modules/systestmodule', 'system/modules'); FileSystemTools::copyRecursive(getenv('thisTestRun_testRunnerPath') . '/modules/testmodule', 'modules'); $paths = $this->getTestTemplateFiles(); foreach ($paths as $path) { $file = $this->ROOT_PATH . "/" . $path . ".tpl.php"; if (!is_dir(dirname($file))) { mkdir(dirname($file), 0777, true); } file_put_contents($file, ':::TEMPLATE:::' . $file . "::"); } // write module config file_put_contents($this->ROOT_PATH . "/system/modules/systestmodule/config.php", '<' . '?php Config::set("systestmodule",["testing"=>"fred","active"=>true,"topmenu"=>false,"path"=>"system/modules","hooks"=>["systestmodule","core_web","core_dbobject"]]);'); file_put_contents($this->ROOT_PATH . "/modules/testmodule/config.php", '<' . '?php Config::set("testmodule",["testing"=>"fred","active"=>true,"topmenu"=>false,"path"=>"modules","hooks"=>["systestmodule","core_web","core_dbobject"]]);'); // hooks file $content = '<' . '?php'; // web hooks foreach (['testmodule_core_web_testhooks', 'testmodule_core_web_testhooks_ping', 'testmodule_core_web_testhooks_ping_testmodule', 'testmodule_core_web_testhooks_ping_testmodule_submodule', 'testmodule_core_web_testhooks_ping_testmodule_submodule_sleep', 'testmodule_core_web_testhooks_ping_testmodule_sleep'] as $hookFunction) { $content .= ' function ' . $hookFunction . '($w,$a) { echo ":::HOOK:::' . $hookFunction . ':::"; }' . "\n"; } // db hooks foreach (['testmodule_core_dbobject_before_insert', 'testmodule_core_dbobject_after_insert', 'testmodule_core_dbobject_before_update', 'testmodule_core_dbobject_after_update', 'testmodule_core_dbobject_before_delete', 'testmodule_core_dbobject_after_delete', 'testmodule_core_dbobject_before_insert_TestmoduleData', 'testmodule_core_dbobject_after_insert_TestmoduleData', 'testmodule_core_dbobject_before_update_before_TestmoduleData', 'testmodule_core_dbobject_after_update_TestmoduleData', 'testmodule_core_dbobject_before_delete_TestmoduleData', 'testmodule_core_dbobject_after_delete_TestmoduleData', 'testmodule_core_dbobject_indexChange_TestmoduleData'] as $hookFunction) { //$content.=' function '.$hookFunction.'($w,$a) { echo ":::DBHOOK:::'.$hookFunction.':::"; }'."\n"; } // write hooks file $content .= ' function systestmodule_systestmodule_dostuff($w,$a) {echo ":::".$w->_module.":::".$a.":::stuff done";}' . "\n"; file_put_contents($this->ROOT_PATH . "/system/modules/systestmodule/systestmodule.hooks.php", $content); // partial in testmodule @mkdir($this->ROOT_PATH . "/modules/testmodule/mypartials"); @mkdir($this->ROOT_PATH . "/modules/testmodule/mypartials/actions"); @mkdir($this->ROOT_PATH . "/modules/testmodule/mypartials/templates"); file_put_contents($this->ROOT_PATH . "/modules/testmodule/mypartials/actions/testpartial.php", '<' . '?php ' . 'function testpartial_ALL(Web $w,$params) { $w->ctx("partialvalue","thepartialvalue".$params["paramsvalue"]);} ;'); file_put_contents($this->ROOT_PATH . "/modules/testmodule/mypartials/templates/testpartial.tpl.php", '<' . '?php ' . 'echo "testpartial:::".$partialvalue.":::";'); // action and template for sys test module @mkdir($this->ROOT_PATH . "/system/modules/systestmodule/actions"); file_put_contents($this->ROOT_PATH . "/system/modules/systestmodule/actions/fail.php", '<' . '?php ' . 'function fail_ALL(Web $w) { $w->ctx("testactionvalue","failedthetest");} ;'); // action and template for test module @mkdir($this->ROOT_PATH . "/modules/testmodule/actions"); @mkdir($this->ROOT_PATH . "/modules/testmodule/templates"); file_put_contents($this->ROOT_PATH . "/modules/testmodule/actions/testaction.php", '<' . '?php ' . 'function testaction_ALL(Web $w) { $w->ctx("testactionvalue","thevalue");} ;'); file_put_contents($this->ROOT_PATH . "/modules/testmodule/templates/testaction.tpl.php", '<' . '?php ' . 'echo "testaction:::".$testactionvalue.":::";'); // minimum layout template file_put_contents($this->ROOT_PATH . "/templates/minilayout.tpl.php", '<' . '?php ' . 'echo "MINILAYOUT||"; echo !empty($body) ? $body : ""; echo "||"; '); }
static function runTests($testFolder) { $output = []; // clean staging $cmds = array(); $staging = TestConfig::getConfig('testStagingPath'); //FileSystemTools::setPermissionsAllowEveryone($staging); //FileSystemTools::setPermissionsAllowEveryone(TestConfig::getConfig('testOutputPath')); $passedAllTests = true; // some sanity checking before pruning if (strlen(trim($staging)) > 0) { // clean up staging FileSystemTools::prune($staging); //return array(); // create staging location @mkdir($staging . DS . 'tests', 0777, true); @mkdir($staging . DS . 'tests' . DS . '_support', 0777, true); // copy shared test support files FileSystemTools::copyRecursive(TestConfig::getConfig('testSharedSupportPath'), $staging . DS . 'tests' . DS . '_support'); //return array(); // then copy over the top, test suites etc to staging FileSystemTools::copyRecursive($testFolder, $staging . DS . 'tests'); // ensure required test directories @mkdir($staging . DS . 'tests' . DS . '_support', 0777, true); @mkdir($staging . DS . 'tests' . DS . '_output', 0777, true); @mkdir($staging . DS . 'tests' . DS . '_data', 0777, true); @mkdir($staging . DS . 'tests' . DS . '_support' . DS . 'Helper', 0777, true); TestConfig::writeCodeceptionConfig(); $objects = glob($staging . DS . 'tests' . DS . '*.suite.yml'); if (sizeof($objects) > 0) { foreach ($objects as $file) { if ($file == "." || $file == "..") { continue; } TestConfig::writeWebDriverConfig($file); } } // cm5? if (strlen(trim(TestConfig::getConfig('cmFivePath'))) > 0) { // copy installer sql to test data directory copy(TestConfig::getConfig('cmFivePath') . DS . 'cache' . DS . 'install.sql', $staging . DS . 'tests' . DS . '_data' . DS . 'dump.sql'); // copy c3.php for accptance test coverage if (TestConfig::getConfig('coverage')) { copy(TestConfig::getConfig('testRunnerPath') . DS . 'src' . DS . 'lib' . DS . 'c3.php', TestConfig::getConfig('testRunnerPath') . DS . 'staging' . DS . 'c3.php'); } } // build and run array_push($cmds, array('CODECEPTION BUILD', TestConfig::getConfig('codeception') . ' build ' . ' -c ' . $staging)); $testParam = TestConfig::getConfig('testSuite'); $testParam .= strlen(trim(TestConfig::getConfig('testSuite'))) > 0 ? ' ' . TestConfig::getConfig('test') : ''; // these options conflict with coverage options below so only one set $coverage = ' -d --no-colors --steps '; if (TestConfig::getConfig('coverage')) { //--coverage-xml $coverage = ' --coverage --xml --html --coverage-html --report '; } array_push($cmds, array('CODECEPTION RUN', TestConfig::getConfig('codeception') . ' run ' . $coverage . ' -c ' . $staging . ' ' . $testParam)); foreach ($cmds as $cmd) { if (php_sapi_name() == 'cli') { echo "-------------------------------------------------\n"; echo $cmd[0] . "\n"; echo $cmd[1] . "\n"; echo "-------------------------------------------------\n"; } else { $output[] = "-------------------------------------------------"; $output[] = $cmd[0]; $output[] = $cmd[1]; $output[] = "-------------------------------------------------"; } $handle = popen($cmd[1], "r"); $detailsTest = ''; $errorActive = false; $testType = ''; while (!feof($handle)) { $buffer = fgets($handle); //$buffer = trim(htmlspecialchars($buffer)); if (php_sapi_name() == 'cli') { echo $buffer; } else { $output[] = trim($buffer); } } $exitCode = pclose($handle); if ($exitCode > 0) { $passedAllTests = false; } } // save output files $testSuiteName = str_replace(':', '_', str_replace(DS, '_', $testFolder)); @mkdir(TestConfig::getConfig('testOutputPath') . DS . $testSuiteName); $output[] = "COPY test results from " . $staging . DS . 'tests' . DS . '_output' . " to " . TestConfig::getConfig('testOutputPath') . DS . $testSuiteName; FileSystemTools::copyRecursive($staging . DS . 'tests' . DS . '_output', TestConfig::getConfig('testOutputPath') . DS . $testSuiteName); } // clean up if (strlen(trim(TestConfig::getConfig('testRunnerPath'))) > 0 && file_exists(TestConfig::getConfig("testRunnerPath") . "/staging/c3.php")) { //unlink(TestConfig::getConfig("testRunnerPath")."/staging/c3.php"); } //FileSystemTools::setPermissionsAllowEveryone($staging); //FileSystemTools::setPermissionsAllowEveryone(TestConfig::getConfig('testOutputPath')); return array('output' => $output, 'result' => $passedAllTests); }
static function copyRecursive($path, $dest, $perms = null) { // echo "COPY REC ".$path." to ".$dest."\n"; @mkdir($dest, 0777, true); $tests = array(); if (is_dir($path)) { $objects = scandir($path); if (sizeof($objects) > 0) { foreach ($objects as $file) { if ($file == "." || $file == "..") { continue; } // go on if (is_dir($path . DS . $file)) { FileSystemTools::copyRecursive($path . DS . $file, $dest . DS . $file); } else { copy($path . DS . $file, $dest . DS . $file); if (!empty($perms)) { chmod($dest . DS . $file, $perms); } @chgrp($dest . DS . $file, FileSystemTools::$webServerUser); } } } } }