Best Atoum code snippet using cli.testClass
webrunner.php
Source:webrunner.php
1<?php2// This file is part of Moodle - http://moodle.org/3//4// Moodle is free software: you can redistribute it and/or modify5// it under the terms of the GNU General Public License as published by6// the Free Software Foundation, either version 3 of the License, or7// (at your option) any later version.8//9// Moodle is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the12// GNU General Public License for more details.13//14// You should have received a copy of the GNU General Public License15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.16/**17 * PHPUnit shell execution wrapper18 *19 * @package tool_phpunit20 * @copyright 2012 Petr Skoda {@link http://skodak.org}21 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later22 */23define('NO_OUTPUT_BUFFERING', true);24require(__DIR__ . '/../../../config.php');25require_once($CFG->libdir.'/adminlib.php');26$testpath = optional_param('testpath', '', PARAM_PATH);27$testclass = optional_param('testclass', '', PARAM_ALPHANUMEXT);28$execute = optional_param('execute', 0, PARAM_BOOL);29navigation_node::override_active_url(new moodle_url('/admin/tool/phpunit/index.php'));30admin_externalpage_setup('toolphpunitwebrunner');31if (!$CFG->debugdeveloper) {32 print_error('notlocalisederrormessage', 'error', '', null, 'Not available on production sites, sorry.');33}34core_php_time_limit::raise(60*30);35$oldcwd = getcwd();36$code = 0;37if (!isset($CFG->phpunit_dataroot) or !isset($CFG->phpunit_prefix)) {38 tool_phpunit_problem('Missing $CFG->phpunit_dataroot or $CFG->phpunit_prefix, can not execute tests.');39}40if (!file_exists($CFG->phpunit_dataroot)) {41 mkdir($CFG->phpunit_dataroot, 02777, true);42}43if (!is_writable($CFG->phpunit_dataroot)) {44 tool_phpunit_problem('$CFG->phpunit_dataroot in not writable, can not execute tests.');45}46$output = null;47exec('php --version', $output, $code);48if ($code != 0) {49 tool_phpunit_problem('Can not execute \'php\' binary.');50}51if ($execute) {52 require_sesskey();53 chdir($CFG->dirroot);54 $output = null;55 exec("php $CFG->admin/tool/phpunit/cli/util.php --diag", $output, $code);56 if ($code == 0) {57 // everything is ready58 } else if ($code == PHPUNIT_EXITCODE_INSTALL) {59 tool_phpunit_header();60 echo $OUTPUT->box_start('generalbox');61 echo '<pre>';62 echo "Initialising test database:\n\n";63 chdir($CFG->dirroot);64 ignore_user_abort(true);65 passthru("php $CFG->admin/tool/phpunit/cli/util.php --buildconfig", $code);66 passthru("php $CFG->admin/tool/phpunit/cli/util.php --install", $code);67 chdir($oldcwd);68 echo '</pre>';69 echo $OUTPUT->box_end();70 if ($code != 0) {71 tool_phpunit_problem('Can not initialize database');72 }73 set_debugging(DEBUG_NONE, false); // Hack: no redirect warning, we really want to redirect.74 redirect(new moodle_url($PAGE->url, array('execute'=>1, 'tespath'=>$testpath, 'testclass'=>$testclass, 'sesskey'=>sesskey())), 'Reloading page');75 echo $OUTPUT->footer();76 die();77 } else if ($code == PHPUNIT_EXITCODE_REINSTALL) {78 tool_phpunit_header();79 echo $OUTPUT->box_start('generalbox');80 echo '<pre>';81 echo "Reinitialising test database:\n\n";82 chdir($CFG->dirroot);83 ignore_user_abort(true);84 passthru("php $CFG->admin/tool/phpunit/cli/util.php --drop", $code);85 passthru("php $CFG->admin/tool/phpunit/cli/util.php --buildconfig", $code);86 passthru("php $CFG->admin/tool/phpunit/cli/util.php --install", $code);87 chdir($oldcwd);88 echo '</pre>';89 echo $OUTPUT->box_end();90 if ($code != 0) {91 tool_phpunit_problem('Can not initialize database');92 }93 set_debugging(DEBUG_NONE, false); // Hack: no redirect warning, we really want to redirect.94 redirect(new moodle_url($PAGE->url, array('execute'=>1, 'tespath'=>$testpath, 'testclass'=>$testclass, 'sesskey'=>sesskey())), 'Reloading page');95 die();96 } else {97 tool_phpunit_header();98 echo $OUTPUT->box_start('generalbox');99 echo '<pre>';100 echo "Error: $code\n\n";101 echo implode("\n", $output);102 echo '</pre>';103 echo $OUTPUT->box_end();104 tool_phpunit_problem('Can not execute tests');105 die();106 }107 tool_phpunit_header();108 echo $OUTPUT->box_start('generalbox');109 echo '<pre>';110 // use the dataroot file111 $configdir = "$CFG->phpunit_dataroot/phpunit/webrunner.xml";112 if (!file_exists($configdir)) {113 passthru("php $CFG->admin/tool/phpunit/cli/util.php --buildconfig", $code);114 if ($code != 0) {115 tool_phpunit_problem('Can not create configuration file');116 }117 }118 chdir($CFG->dirroot);119 $configdir = escapeshellarg($configdir);120 $cleanclass = escapeshellarg($testclass);121 $cleanpath = escapeshellarg($testpath);122 passthru("php $CFG->admin/tool/phpunit/cli/util.php --run -c $configdir $cleanclass $cleanpath", $code);123 chdir($oldcwd);124 echo '</pre>';125 echo $OUTPUT->box_end();126} else {127 tool_phpunit_header();128}129echo $OUTPUT->box_start('generalbox boxwidthwide boxaligncenter');130echo '<form method="post" action="webrunner.php">';131echo '<fieldset class="invisiblefieldset">';132echo '<label for="testpath">Test one file</label> ';133echo '<input type="text" id="testpath" name="testpath" value="'.s($testpath).'" size="50" /> (all test cases from webrunner.xml if empty)';134echo '</p>';135echo '<label for="testclass">Class name</label> ';136echo '<input type="text" id="testclass" name="testclass" value="'.s($testclass).'" size="50" /> (first class in file if empty)';137echo '</p>';138echo '<input type="submit" value="Run" />';139echo '<input type="hidden" name="execute" value="1" />';140echo '<input type="hidden" name="sesskey" value="'.sesskey().'" />';141echo '</fieldset>';142echo '</form>';143echo $OUTPUT->box_end();144echo $OUTPUT->footer();145die;146//========================================147/**148 * Print headers and experimental warning149 * @return void150 */151function tool_phpunit_header() {152 global $OUTPUT;153 echo $OUTPUT->header();154 echo $OUTPUT->heading(get_string('pluginname', 'tool_phpunit'));155 echo $OUTPUT->box('EXPERIMENTAL: it is recommended to execute PHPUnit tests and init scripts only from command line.', array('generalbox'));156}157/**158 * Called when PHPUnit can not execute.159 * @param string $message160 * @return void161 */162function tool_phpunit_problem($message) {163 global $PAGE;164 if (!$PAGE->headerprinted) {165 tool_phpunit_header();166 }167 notice($message, new moodle_url('/admin/tool/phpunit/'));168}...
testClass
Using AI Code Generation
1$cli = new cli();2$cli->testClass();3$cli = new cli();4$cli->testClass();5$cli = new cli();6$cli->testClass();7$cli = new cli();8$cli->testClass();9$cli = new cli();10$cli->testClass();11$cli = new cli();12$cli->testClass();13$cli = new cli();14$cli->testClass();15$cli = new cli();16$cli->testClass();17$cli = new cli();18$cli->testClass();19$cli = new cli();20$cli->testClass();21$cli = new cli();22$cli->testClass();23$cli = new cli();24$cli->testClass();25$cli = new cli();26$cli->testClass();27$cli = new cli();28$cli->testClass();29$cli = new cli();30$cli->testClass();31$cli = new cli();32$cli->testClass();33$cli = new cli();34$cli->testClass();
testClass
Using AI Code Generation
1$cli = new cli();2$cli->testClass();3class cli {4 function testClass() {5 echo "This is test class";6 }7}8$cli = new cli();9$cli->testClass();10class cli {11 function testClass() {12 echo "This is test class";13 }14}15$cli = new cli();16$cli->testClass();17class cli {18 function testClass() {19 echo "This is test class";20 }21}22$cli = new cli();23$cli->testClass();24class cli {25 function testClass() {26 echo "This is test class";27 }28}29$cli = new cli();30$cli->testClass();31class cli {32 function testClass() {33 echo "This is test class";34 }35}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with testClass on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!