3 * Code quality unit tests that are so slow you don't want to run them every time.
5 * @copyright © 2006 The Open University
6 * @author T.J.Hunt@open.ac.uk
7 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
8 * @package SimpleTestEx
11 if (!defined('MOODLE_INTERNAL')) {
12 die('Direct access to this script is forbidden.'); /// It must be included from a Moodle page
15 class slow_code_test
extends UnitTestCase
{
16 var $php_code_extensions = array('php', 'html', 'php\.inc');
17 var $ignore_folders = array();
20 function prepend_dirroot($string) {
22 return $CFG->dirroot
. $string;
25 function test_php_syntax() {
28 // See if we can run php from the command line:
29 $this->phppath
= 'php';
30 if (!shell_exec($this->phppath
. ' -v')) {
31 // If not, we can't do anything.
32 $this->fail('Cannot test PHP syntax because PHP is not on the path.');
36 $regexp = '/\.(' . implode('|', $this->php_code_extensions
) . ')$/';
37 $ignore = array_map(array($this, 'prepend_dirroot'), $this->ignore_folders
);
38 recurseFolders($CFG->dirroot
, array($this, 'syntax_check_file'), $regexp, false, $ignore);
42 function syntax_check_file($filepath) {
43 // If you don't print something for each test, then for some reason the
44 // server hangs after a thousand files or so. It is very intermittent.
45 // Printing a space does not seem to be good enough.
47 if (++
$this->dotcount %
100 == 0) {
51 $output = shell_exec($this->phppath
. ' -d max_execution_time=5 -d short_open_tag= -l ' . escapeshellarg($filepath));
52 $this->assertTrue(strpos($output, 'No syntax errors detected') === 0, $output);
53 // This generates so many fails that it is currently useless.
54 // $this->assertTrue(stripos(file_get_contents($filepath), "\t") === false,
55 // "File $filepath contains a tab character.");