This commit is contained in:
Eloy Lafuente (stronk7) 2016-04-06 00:12:00 +02:00
commit f6825a62ef
5 changed files with 118 additions and 17 deletions

View File

@ -0,0 +1,34 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Display environment used for running behat.
*
* This file is used for behat testing to ensure cli and apache
* version of environment is same.
*
* @package tool_behat
* @copyright 2016 onwards Rajesh Taneja
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
require_once(__DIR__.'/../../../../../../config.php');
// Only continue for behat site.
defined('BEHAT_SITE_RUNNING') || die();
require_once($CFG->libdir.'/behat/classes/util.php');
echo json_encode(behat_util::get_environment(), true);

View File

@ -138,20 +138,42 @@ class behat_util extends testing_util {
}
/**
* Checks if $CFG->behat_wwwroot is available
* Checks if $CFG->behat_wwwroot is available and using same versions for cli and web.
*
* @return bool
* @return void
*/
public static function is_server_running() {
public static function check_server_status() {
global $CFG;
$request = new curl();
$request->get($CFG->behat_wwwroot);
$url = $CFG->behat_wwwroot . '/admin/tool/behat/tests/behat/fixtures/environment.php';
if ($request->get_errno() === 0) {
return true;
// Get web versions used by behat site.
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
if (empty($result)) {
behat_error (BEHAT_EXITCODE_REQUIREMENT, $CFG->behat_wwwroot . ' is not available, ensure you specified ' .
'correct url and that the server is set up and started.' . PHP_EOL . ' More info in ' .
behat_command::DOCS_URL . '#Running_tests' . PHP_EOL);
}
// Check if cli version is same as web version.
$result = json_decode($result, true);
$clienv = self::get_environment();
if ($result != $clienv) {
$output = 'Differences decteted between cli and webserver...'.PHP_EOL;
foreach ($result as $key => $version) {
if ($clienv[$key] != $version) {
$output .= ' ' . $key . ': ' . PHP_EOL;
$output .= ' - web server: ' . $version . PHP_EOL;
$output .= ' - cli: ' . $clienv[$key] . PHP_EOL;
}
}
echo $output;
}
return false;
}
/**

View File

@ -832,16 +832,24 @@ abstract class testing_util {
$output = '';
// All developers have to understand English, do not localise!
$env = self::get_environment();
$release = null;
require("$CFG->dirroot/version.php");
$output .= "Moodle $release, $CFG->dbtype";
$output .= "Moodle ".$env['moodleversion'];
if ($hash = self::get_git_hash()) {
$output .= ", $hash";
}
$output .= "\n";
// Add php version.
require_once($CFG->libdir.'/environmentlib.php');
$output .= "Php: ". normalize_version($env['phpversion']);
// Add database type and version.
$output .= ", " . $env['dbtype'] . ": " . $env['dbversion'];
// OS details.
$output .= ", OS: " . $env['os'] . "\n";
return $output;
}
@ -1068,4 +1076,43 @@ abstract class testing_util {
fclose($fp);
}
}
/**
* Return list of environment versions on which tests will run.
* Environment includes:
* - moodleversion
* - phpversion
* - dbtype
* - dbversion
* - os
*
* @return array
*/
public static function get_environment() {
global $CFG, $DB;
$env = array();
// Add moodle version.
$release = null;
require("$CFG->dirroot/version.php");
$env['moodleversion'] = $release;
// Add php version.
$phpversion = phpversion();
$env['phpversion'] = $phpversion;
// Add database type and version.
$dbtype = $DB->get_dbvendor();
$dbinfo = $DB->get_server_info();
$dbversion = $dbinfo['version'];
$env['dbtype'] = ucfirst($dbtype);
$env['dbversion'] = $dbversion;
// OS details.
$osdetails = php_uname('s') . " " . php_uname('r') . " " . php_uname('m');
$env['os'] = $osdetails;
return $env;
}
}

View File

@ -139,11 +139,8 @@ class behat_hooks extends behat_base {
// If not done, then it can return apache error, while running tests.
behat_util::reset_all_data();
if (!behat_util::is_server_running()) {
throw new Exception($CFG->behat_wwwroot .
' is not available, ensure you specified correct url and that the server is set up and started.' .
' More info in ' . behat_command::DOCS_URL . '#Running_tests');
}
// Check if server is running and using same version for cli and apache.
behat_util::check_server_status();
// Prevents using outdated data, upgrade script would start and tests would fail.
if (!behat_util::is_test_data_updated()) {

View File

@ -105,6 +105,7 @@ information provided here is intended especially for developers.
* Any plugin can report when a scale is being used with the callback function [pluginname]_scale_used_anywhere(int $scaleid).
* Changes in file_rewrite_pluginfile_urls: Passing a new option reverse = true in the $options var will make the function to convert
actual URLs in $text to encoded URLs in the @@PLUGINFILE@@ form.
* behat_util::is_server_running() is removed, please use behat_util::check_server_status() instead.
=== 3.0 ===