Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Differences Between: [Versions 310 and 311] [Versions 311 and 400] [Versions 311 and 401] [Versions 311 and 402] [Versions 311 and 403] [Versions 39 and 311]

   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (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 of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Coverage information for PHPUnit.
  19   *
  20   * @package    core
  21   * @category   phpunit
  22   * @copyright  2018 Andrew Nicols <andrew@nicols.co.uk>
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  defined('MOODLE_INTERNAL') || die();
  27  
  28  /**
  29   * Coverage information for PHPUnit.
  30   *
  31   * @copyright  2018 Andrew Nicols <andrew@nicols.co.uk>
  32   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  33   */
  34  class phpunit_coverage_info {
  35  
  36      /**
  37       * @var array The list of folders relative to the plugin root to whitelist in coverage generation.
  38       * @deprecated since Moodle 3.11 MDL-70745 - please don't use this property any more.
  39       * @todo MDL-71067 - remove in Moodle 4.3
  40       */
  41      protected $whitelistfolders = [];
  42  
  43      /**
  44       * @var array The list of files relative to the plugin root to whitelist in coverage generation.
  45       * @deprecated since Moodle 3.11 MDL-70745 - please don't use this property any more.
  46       * @todo MDL-71067 - remove in Moodle 4.3
  47       */
  48      protected $whitelistfiles = [];
  49  
  50      /** @var array The list of folders relative to the plugin root to include in coverage generation. */
  51      protected $includelistfolders = [];
  52  
  53      /** @var array The list of files relative to the plugin root to include in coverage generation. */
  54      protected $includelistfiles = [];
  55  
  56      /** @var array The list of folders relative to the plugin root to exclude from coverage generation. */
  57      protected $excludelistfolders = [];
  58  
  59      /** @var array The list of files relative to the plugin root to exclude from coverage generation. */
  60      protected $excludelistfiles = [];
  61  
  62      /**
  63       * Get the formatted XML list of files and folders to include.
  64       *
  65       * @param   string  $plugindir The root of the plugin, relative to the dataroot.
  66       * @return  array
  67       */
  68      final public function get_includelists(string $plugindir) : array {
  69          $coverages = [];
  70  
  71          if (!empty($plugindir)) {
  72              $plugindir .= "/";
  73  
  74              // TODO: MDL-71067 - remove this whole block once these properties deprecation period ends.
  75              if (!empty($this->whitelistfolders) || !empty($this->whitelistfiles)) {
  76                  // Warning if the deprecated (whitelist) properties are found.
  77                  echo "Warning: \$whitelistfolders and \$whitelistfiles in " .
  78                      "coverage.php files are deprecated since Moodle 3.11. " .
  79                      "Please, replace them with \$includelistfolders and " .
  80                      "\$includelistfiles in {$plugindir}tests/coverage.php\n";
  81  
  82                  foreach ($this->whitelistfolders as $folder) {
  83                      $coverages[] = html_writer::tag('directory', "{$plugindir}{$folder}", ['suffix' => '.php']);
  84                  }
  85  
  86                  foreach ($this->whitelistfiles as $file) {
  87                      $coverages[] = html_writer::tag('file', "{$plugindir}{$file}");
  88                  }
  89              }
  90          }
  91  
  92          foreach ($this->includelistfolders as $folder) {
  93              $coverages[] = html_writer::tag('directory', "{$plugindir}{$folder}", ['suffix' => '.php']);
  94          }
  95  
  96          foreach ($this->includelistfiles as $file) {
  97              $coverages[] = html_writer::tag('file', "{$plugindir}{$file}");
  98          }
  99  
 100          return $coverages;
 101      }
 102  
 103      /**
 104       * Get the formatted XML list of files and folders to exclude.
 105       *
 106       * @param   string  $plugindir The root of the plugin, relative to the dataroot.
 107       * @return  array
 108       */
 109      final public function get_excludelists(string $plugindir) : array {
 110          $coverages = [];
 111  
 112          if (!empty($plugindir)) {
 113              $plugindir .= "/";
 114          }
 115  
 116          foreach ($this->excludelistfolders as $folder) {
 117              $coverages[] = html_writer::tag('directory', "{$plugindir}{$folder}", ['suffix' => '.php']);
 118          }
 119  
 120          foreach ($this->excludelistfiles as $file) {
 121              $coverages[] = html_writer::tag('file', "{$plugindir}{$file}");
 122          }
 123  
 124          return $coverages;
 125      }
 126  }