Ejemplo n.º 1
0
 /**
  * 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);
     // Gets all the components with tests
     $components = tests_finder::get_components_with_tests('phpunit');
     // 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)) {
                 testing_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");
         }
     }
 }
 /**
  * Gets the list of Moodle steps definitions
  *
  * Class name as a key and the filepath as value
  *
  * Externalized from update_config_file() to use
  * it from the steps definitions web interface
  *
  * @return array
  */
 public static function get_components_steps_definitions()
 {
     $components = tests_finder::get_components_with_tests('stepsdefinitions');
     if (!$components) {
         return false;
     }
     $stepsdefinitions = array();
     foreach ($components as $componentname => $componentpath) {
         $componentpath = self::clean_path($componentpath);
         if (!file_exists($componentpath . self::get_behat_tests_path())) {
             continue;
         }
         $diriterator = new DirectoryIterator($componentpath . self::get_behat_tests_path());
         $regite = new RegexIterator($diriterator, '|behat_.*\\.php$|');
         // All behat_*.php inside behat_config_manager::get_behat_tests_path() are added as steps definitions files.
         foreach ($regite as $file) {
             $key = $file->getBasename('.php');
             $stepsdefinitions[$key] = $file->getPathname();
         }
     }
     return $stepsdefinitions;
 }
Ejemplo n.º 3
0
 /**
  * List of components which contain behat context or features.
  *
  * @return array
  */
 private function get_components_with_tests()
 {
     if (empty($this->componentswithtests)) {
         $this->componentswithtests = tests_finder::get_components_with_tests('behat');
     }
     return $this->componentswithtests;
 }
Ejemplo n.º 4
0
 /**
  * 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@_testsuite">
             <directory suffix="_test.php">.</directory>
         </testsuite>
     </testsuites>';
     // Start a sequence between 100000 and 199000 to ensure each call to init produces
     // different ids in the database.  This reduces the risk that hard coded values will
     // end up being placed in phpunit or behat test code.
     $sequencestart = 100000 + mt_rand(0, 99) * 1000;
     // 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);
     // Gets all the components with tests
     $components = tests_finder::get_components_with_tests('phpunit');
     // 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);
         $fcontents = str_replace('<const name="PHPUNIT_SEQUENCE_START" value=""/>', '<const name="PHPUNIT_SEQUENCE_START" value="' . $sequencestart . '"/>', $fcontents);
         // 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)) {
                 testing_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");
         }
     }
 }