コード例 #1
0
ファイル: bootstraplib.php プロジェクト: robadobdob/moodle
/**
 * Mark empty dataroot to be used for testing.
 * @param string $dataroot The dataroot directory
 * @return void
 */
function phpunit_bootstrap_initdataroot($dataroot)
{
    global $CFG;
    umask(0);
    if (!file_exists("{$dataroot}/phpunittestdir.txt")) {
        file_put_contents("{$dataroot}/phpunittestdir.txt", 'Contents of this directory are used during tests only, do not delete this file!');
    }
    phpunit_boostrap_fix_file_permissions("{$dataroot}/phpunittestdir.txt");
    if (!file_exists("{$CFG->phpunit_dataroot}/phpunit")) {
        mkdir("{$CFG->phpunit_dataroot}/phpunit", $CFG->directorypermissions);
    }
}
コード例 #2
0
ファイル: util.php プロジェクト: nigeli/moodle
 /**
  * Builds phpunit.xml files for all components using defaults from /phpunit.xml.dist
  *
  * @static
  * @return void, stops if can not write files
  */
 public static function build_component_config_files()
 {
     global $CFG;
     $template = '
     <testsuites>
         <testsuite name="@component@">
             <directory suffix="_test.php">.</directory>
         </testsuite>
     </testsuites>';
     // Use the upstream file as source for the distributed configurations
     $ftemplate = file_get_contents("{$CFG->dirroot}/phpunit.xml.dist");
     $ftemplate = preg_replace('|<!--All core suites.*</testsuites>|s', '<!--@component_suite@-->', $ftemplate);
     // Get all the components
     $components = self::get_all_plugins_with_tests() + self::get_all_subsystems_with_tests();
     // Get all the directories having tests
     $directories = self::get_all_directories_with_tests();
     // Find any directory not covered by proper components
     $remaining = array_diff($directories, $components);
     // Add them to the list of components
     $components += $remaining;
     // Create the corresponding phpunit.xml file for each component
     foreach ($components as $cname => $cpath) {
         // Calculate the component suite
         $ctemplate = $template;
         $ctemplate = str_replace('@component@', $cname, $ctemplate);
         // Apply it to the file template
         $fcontents = str_replace('<!--@component_suite@-->', $ctemplate, $ftemplate);
         // fix link to schema
         $level = substr_count(str_replace('\\', '/', $cpath), '/') - substr_count(str_replace('\\', '/', $CFG->dirroot), '/');
         $fcontents = str_replace('lib/phpunit/', str_repeat('../', $level) . 'lib/phpunit/', $fcontents);
         // Write the file
         $result = false;
         if (is_writable($cpath)) {
             if ($result = (bool) file_put_contents("{$cpath}/phpunit.xml", $fcontents)) {
                 phpunit_boostrap_fix_file_permissions("{$cpath}/phpunit.xml");
             }
         }
         // Problems writing file, throw error
         if (!$result) {
             phpunit_bootstrap_error(PHPUNIT_EXITCODE_CONFIGWARNING, "Can not create {$cpath}/phpunit.xml configuration file, verify dir permissions");
         }
     }
 }
コード例 #3
0
ファイル: lib.php プロジェクト: numbas/moodle
 /**
  * Builds dirroot/phpunit.xml and dataroot/phpunit/webrunner.xml files using defaults from /phpunit.xml.dist
  * @static
  * @return bool true means main config file created, false means only dataroot file created
  */
 public static function build_config_file()
 {
     global $CFG;
     $template = '
     <testsuite name="@component@">
         <directory suffix="_test.php">@dir@</directory>
     </testsuite>';
     $data = file_get_contents("{$CFG->dirroot}/phpunit.xml.dist");
     $suites = '';
     $plugintypes = get_plugin_types();
     ksort($plugintypes);
     foreach ($plugintypes as $type => $unused) {
         $plugs = get_plugin_list($type);
         ksort($plugs);
         foreach ($plugs as $plug => $fullplug) {
             if (!file_exists("{$fullplug}/tests/")) {
                 continue;
             }
             $dir = substr($fullplug, strlen($CFG->dirroot) + 1);
             $dir .= '/tests';
             $component = $type . '_' . $plug;
             $suite = str_replace('@component@', $component, $template);
             $suite = str_replace('@dir@', $dir, $suite);
             $suites .= $suite;
         }
     }
     $data = preg_replace('|<!--@plugin_suites_start@-->.*<!--@plugin_suites_end@-->|s', $suites, $data, 1);
     $result = false;
     if (is_writable($CFG->dirroot)) {
         if ($result = file_put_contents("{$CFG->dirroot}/phpunit.xml", $data)) {
             phpunit_boostrap_fix_file_permissions("{$CFG->dirroot}/phpunit.xml");
         }
     }
     // relink - it seems that xml:base does not work in phpunit xml files, remove this nasty hack if you find a way to set xml base for relative refs
     $data = str_replace('lib/phpunit/', $CFG->dirroot . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'phpunit' . DIRECTORY_SEPARATOR, $data);
     $data = preg_replace('|<directory suffix="_test.php">([^<]+)</directory>|', '<directory suffix="_test.php">' . $CFG->dirroot . (DIRECTORY_SEPARATOR === '\\' ? '\\\\' : DIRECTORY_SEPARATOR) . '$1</directory>', $data);
     file_put_contents("{$CFG->dataroot}/phpunit/webrunner.xml", $data);
     phpunit_boostrap_fix_file_permissions("{$CFG->dataroot}/phpunit/webrunner.xml");
     return (bool) $result;
 }