From 3a70983d5313d97e6b59945102b820a039acb3a5 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Mon, 27 Sep 2021 09:39:00 +0800 Subject: [PATCH] MDL-72701 unit tests: Generate default coverage --- admin/tool/dataprivacy/tests/coverage.php | 49 ------------------- grade/grading/form/guide/tests/coverage.php | 41 ---------------- grade/grading/form/rubric/tests/coverage.php | 41 ---------------- grade/grading/tests/coverage.php | 41 ---------------- grade/tests/coverage.php | 40 ---------------- h5p/tests/coverage.php | 48 ------------------- lib/phpunit/classes/coverage_info.php | 26 ++++++---- lib/phpunit/classes/util.php | 4 +- lib/table/tests/coverage.php | 50 -------------------- lib/tests/coverage.php | 8 ---- lib/upgrade.txt | 10 ++++ lib/xapi/tests/coverage.php | 48 ------------------- mod/forum/tests/coverage.php | 49 ------------------- mod/h5pactivity/tests/coverage.php | 43 ----------------- privacy/tests/coverage.php | 49 ------------------- reportbuilder/tests/coverage.php | 43 ----------------- 16 files changed, 29 insertions(+), 561 deletions(-) delete mode 100644 admin/tool/dataprivacy/tests/coverage.php delete mode 100644 grade/grading/form/guide/tests/coverage.php delete mode 100644 grade/grading/form/rubric/tests/coverage.php delete mode 100644 grade/grading/tests/coverage.php delete mode 100644 grade/tests/coverage.php delete mode 100644 h5p/tests/coverage.php delete mode 100644 lib/table/tests/coverage.php delete mode 100644 lib/xapi/tests/coverage.php delete mode 100644 mod/forum/tests/coverage.php delete mode 100644 mod/h5pactivity/tests/coverage.php delete mode 100644 privacy/tests/coverage.php delete mode 100644 reportbuilder/tests/coverage.php diff --git a/admin/tool/dataprivacy/tests/coverage.php b/admin/tool/dataprivacy/tests/coverage.php deleted file mode 100644 index 8cf8d5d1d09..00000000000 --- a/admin/tool/dataprivacy/tests/coverage.php +++ /dev/null @@ -1,49 +0,0 @@ -. - -defined('MOODLE_INTERNAL') || die(); - -/** - * Coverage information for the tool_dataprivacy plugin. - * - * @package core - * @category phpunit - * @copyright 2018 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -/** - * Coverage information for the tool_dataprivacy plugin. - * - * @copyright 2018 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -return new class extends phpunit_coverage_info { - /** @var array The list of folders relative to the plugin root to include in coverage generation. */ - protected $includelistfolders = [ - 'classes', - ]; - - /** @var array The list of files relative to the plugin root to include in coverage generation. */ - protected $includelistfiles = []; - - /** @var array The list of folders relative to the plugin root to exclude from coverage generation. */ - protected $excludelistfolders = [ - ]; - - /** @var array The list of files relative to the plugin root to exclude from coverage generation. */ - protected $excludelistfiles = []; -}; diff --git a/grade/grading/form/guide/tests/coverage.php b/grade/grading/form/guide/tests/coverage.php deleted file mode 100644 index 4d4db5997e4..00000000000 --- a/grade/grading/form/guide/tests/coverage.php +++ /dev/null @@ -1,41 +0,0 @@ -. - -/** - * Coverage information for the gradingform_guide plugin. - * - * @package gradingform_guide - * @category test - * @copyright 2019 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -/** - * Coverage information for the gradingform_guide plugin. - * - * @package gradingform_guide - * @copyright 2019 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -return new class extends phpunit_coverage_info { - // Array The list of folders relative to the plugin root to include in coverage generation. - protected $includelistfolders = [ - 'classes', - 'tests/generator', - ]; -}; diff --git a/grade/grading/form/rubric/tests/coverage.php b/grade/grading/form/rubric/tests/coverage.php deleted file mode 100644 index 5f7ea0bd9e1..00000000000 --- a/grade/grading/form/rubric/tests/coverage.php +++ /dev/null @@ -1,41 +0,0 @@ -. - -/** - * Coverage information for the gradingform_rubric plugin. - * - * @package gradingform_rubric - * @category test - * @copyright 2019 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -/** - * Coverage information for the gradingform_rubric plugin. - * - * @package gradingform_rubric - * @copyright 2019 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -return new class extends phpunit_coverage_info { - // Array The list of folders relative to the plugin root to include in coverage generation. - protected $includelistfolders = [ - 'classes', - 'tests/generator', - ]; -}; diff --git a/grade/grading/tests/coverage.php b/grade/grading/tests/coverage.php deleted file mode 100644 index ca324a72acf..00000000000 --- a/grade/grading/tests/coverage.php +++ /dev/null @@ -1,41 +0,0 @@ -. - -/** - * Coverage information for the core_grading subsystem. - * - * @package core_grading - * @category test - * @copyright 2019 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -/** - * Coverage information for the core_grading subsystem. - * - * @package core_grading - * @copyright 2019 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -return new class extends phpunit_coverage_info { - // Array The list of folders relative to the plugin root to include in coverage generation. - protected $includelistfolders = [ - 'classes', - 'tests/generator', - ]; -}; diff --git a/grade/tests/coverage.php b/grade/tests/coverage.php deleted file mode 100644 index e94090ee9f5..00000000000 --- a/grade/tests/coverage.php +++ /dev/null @@ -1,40 +0,0 @@ -. - -/** - * Coverage information for the grades component. - * - * @package core_grades - * @category test - * @copyright 2019 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -/** - * Coverage information for the core_grades subsystem. - * - * @package core_grades - * @copyright 2019 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -return new class extends phpunit_coverage_info { - // Array The list of folders relative to the plugin root to include in coverage generation. - protected $includelistfolders = [ - 'classes', - ]; -}; diff --git a/h5p/tests/coverage.php b/h5p/tests/coverage.php deleted file mode 100644 index 2f44b956404..00000000000 --- a/h5p/tests/coverage.php +++ /dev/null @@ -1,48 +0,0 @@ -. - -defined('MOODLE_INTERNAL') || die(); - -/** - * Coverage information for the core_h5p subsystem. - * - * @package core_h5p - * @category phpunit - * @copyright 2019 Amaia Anabitarte - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -/** - * Coverage information for the core H5P subsystem. - * - * @copyright 2019 Amaia Anabitarte - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -return new class extends phpunit_coverage_info { - /** @var array The list of folders relative to the plugin root to include in coverage generation. */ - protected $includelistfolders = [ - 'classes', - ]; - - /** @var array The list of files relative to the plugin root to include in coverage generation. */ - protected $includelistfiles = []; - - /** @var array The list of folders relative to the plugin root to exclude from coverage generation. */ - protected $excludelistfolders = []; - - /** @var array The list of files relative to the plugin root to exclude from coverage generation. */ - protected $excludelistfiles = []; -}; diff --git a/lib/phpunit/classes/coverage_info.php b/lib/phpunit/classes/coverage_info.php index c0d6d470bae..3ad26a91f59 100644 --- a/lib/phpunit/classes/coverage_info.php +++ b/lib/phpunit/classes/coverage_info.php @@ -68,6 +68,19 @@ class phpunit_coverage_info { final public function get_includelists(string $plugindir) : array { $coverages = []; + $includelistfolders = array_merge([ + 'classes', + 'tests/generator', + ], $this->includelistfolders);; + + $includelistfiles = array_merge([ + 'externallib.php', + 'lib.php', + 'locallib.php', + 'renderer.php', + 'rsslib.php', + ], $this->includelistfiles); + if (!empty($plugindir)) { $plugindir .= "/"; @@ -79,21 +92,16 @@ class phpunit_coverage_info { "Please, replace them with \$includelistfolders and " . "\$includelistfiles in {$plugindir}tests/coverage.php\n"; - foreach ($this->whitelistfolders as $folder) { - $coverages[] = html_writer::tag('directory', "{$plugindir}{$folder}", ['suffix' => '.php']); - } - - foreach ($this->whitelistfiles as $file) { - $coverages[] = html_writer::tag('file', "{$plugindir}{$file}"); - } + $includelistfolders = array_merge($includelistfolders, $this->whitelistfolders); + $includelistfiles = array_merge($includelistfiles, $this->whitelistfiles); } } - foreach ($this->includelistfolders as $folder) { + foreach ($includelistfolders as $folder) { $coverages[] = html_writer::tag('directory', "{$plugindir}{$folder}", ['suffix' => '.php']); } - foreach ($this->includelistfiles as $file) { + foreach ($includelistfiles as $file) { $coverages[] = html_writer::tag('file', "{$plugindir}{$file}"); } diff --git a/lib/phpunit/classes/util.php b/lib/phpunit/classes/util.php index 4f8ee14e978..da44065f360 100644 --- a/lib/phpunit/classes/util.php +++ b/lib/phpunit/classes/util.php @@ -973,7 +973,7 @@ class phpunit_util extends testing_util { * @param string $fulldir The directory to find the coverage info file in. * @return phpunit_coverage_info */ - protected static function get_coverage_info(string $fulldir): ?phpunit_coverage_info { + protected static function get_coverage_info(string $fulldir): phpunit_coverage_info { $coverageconfig = "{$fulldir}/tests/coverage.php"; if (file_exists($coverageconfig)) { $coverageinfo = require($coverageconfig); @@ -984,7 +984,7 @@ class phpunit_util extends testing_util { return $coverageinfo; } - return null; + return new phpunit_coverage_info();; } /** diff --git a/lib/table/tests/coverage.php b/lib/table/tests/coverage.php deleted file mode 100644 index eee7b6ceb13..00000000000 --- a/lib/table/tests/coverage.php +++ /dev/null @@ -1,50 +0,0 @@ -. - -declare(strict_types=1); - -defined('MOODLE_INTERNAL') || die(); - -/** - * Coverage information for the core_table component. - * - * @package core_table - * @category test - * @copyright 2020 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -/** - * Coverage information for the core_table subsystem. - * - * @copyright 2020 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -return new class extends phpunit_coverage_info { - /** @var array The list of folders relative to the plugin root to include in coverage generation. */ - protected $includelistfolders = [ - 'classes', - ]; - - /** @var array The list of files relative to the plugin root to include in coverage generation. */ - protected $includelistfiles = []; - - /** @var array The list of folders relative to the plugin root to exclude from coverage generation. */ - protected $excludelistfolders = []; - - /** @var array The list of files relative to the plugin root to exclude from coverage generation. */ - protected $excludelistfiles = []; -}; diff --git a/lib/tests/coverage.php b/lib/tests/coverage.php index 4cf41e8028c..64cfea051b7 100644 --- a/lib/tests/coverage.php +++ b/lib/tests/coverage.php @@ -34,20 +34,12 @@ defined('MOODLE_INTERNAL') || die(); return new class extends phpunit_coverage_info { /** @var array The list of folders relative to the plugin root to include in coverage generation. */ protected $includelistfolders = [ - 'classes', - // This is a legacy hangup which relates to parts of the file storage API being placed in the wrong location. 'filestorage', ]; - /** @var array The list of files relative to the plugin root to include in coverage generation. */ - protected $includelistfiles = []; - /** @var array The list of folders relative to the plugin root to exclude from coverage generation. */ protected $excludelistfolders = [ 'filestorage/tests', ]; - - /** @var array The list of files relative to the plugin root to exclude from coverage generation. */ - protected $excludelistfiles = []; }; diff --git a/lib/upgrade.txt b/lib/upgrade.txt index b92efc0da92..a5dc0d015a5 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -153,6 +153,16 @@ such as the title and strings for continue and cancel buttons. * The method get_enabled_plugin($pluginname) has been added to the core_plugininfo\base class. It has a default implementation for all the plugininfo classes and it can be overwritten when required (like it has been done with filter). This method returns the current value for a pluginname depending on its status (enabled, disabled, other...). +* Unit Test coverage defaults have been updated to include some sensible defaults. + The default values now include: + * /classes/ + * /tests/generator/ + * /externallib.php + * /lib.php + * /locallib.php + * /renderer.php + * /rsslib.php + This default applies both when there is no supplied coverage.php file, and is used to supplement any existing coverage configuration file if one is found. === 3.11.4 === * A new option dontforcesvgdownload has been added to the $options parameter of the send_file() function. diff --git a/lib/xapi/tests/coverage.php b/lib/xapi/tests/coverage.php deleted file mode 100644 index 1a4f28beb5d..00000000000 --- a/lib/xapi/tests/coverage.php +++ /dev/null @@ -1,48 +0,0 @@ -. - -/** - * Coverage information for the core_xapi component. - * - * @package core_xapi - * @category test - * @copyright 2020 Ferran Recio - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -/** - * Coverage information for the core xAPI component. - * - * @copyright 2020 Ferran Recio - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -return new class extends phpunit_coverage_info { - /** @var array The list of folders relative to the plugin root to include in coverage generation. */ - protected $includelistfolders = [ - 'classes', - ]; - - /** @var array The list of files relative to the plugin root to include in coverage generation. */ - protected $includelistfiles = []; - - /** @var array The list of folders relative to the plugin root to exclude from coverage generation. */ - protected $excludelistfolders = []; - - /** @var array The list of files relative to the plugin root to exclude from coverage generation. */ - protected $excludelistfiles = []; -}; diff --git a/mod/forum/tests/coverage.php b/mod/forum/tests/coverage.php deleted file mode 100644 index a9edb2473ed..00000000000 --- a/mod/forum/tests/coverage.php +++ /dev/null @@ -1,49 +0,0 @@ -. - -defined('MOODLE_INTERNAL') || die(); - -/** - * Coverage information for the mod_forum component. - * - * @package mod_forum - * @category phpunit - * @copyright 2019 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -/** - * Coverage information for the core subsystem. - * - * @copyright 2019 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -return new class extends phpunit_coverage_info { - /** @var array The list of folders relative to the plugin root to include in coverage generation. */ - protected $includelistfolders = [ - 'classes', - 'externallib.php', - ]; - - /** @var array The list of files relative to the plugin root to include in coverage generation. */ - protected $includelistfiles = []; - - /** @var array The list of folders relative to the plugin root to exclude from coverage generation. */ - protected $excludelistfolders = []; - - /** @var array The list of files relative to the plugin root to exclude from coverage generation. */ - protected $excludelistfiles = []; -}; diff --git a/mod/h5pactivity/tests/coverage.php b/mod/h5pactivity/tests/coverage.php deleted file mode 100644 index 9902daba6dc..00000000000 --- a/mod/h5pactivity/tests/coverage.php +++ /dev/null @@ -1,43 +0,0 @@ -. - -/** - * Coverage information for the mod_h5pactivity. - * - * @package mod_h5pactivity - * @category test - * @copyright 2021 Ferran Recio - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -defined('MOODLE_INTERNAL') || die(); - -return new class extends phpunit_coverage_info { - /** @var array The list of folders relative to the plugin root to include in coverage generation. */ - protected $includelistfolders = [ - 'classes', - 'tests/generator', - ]; - - /** @var array The list of files relative to the plugin root to include in coverage generation. */ - protected $includelistfiles = []; - - /** @var array The list of folders relative to the plugin root to exclude from coverage generation. */ - protected $excludelistfolders = []; - - /** @var array The list of files relative to the plugin root to exclude from coverage generation. */ - protected $excludelistfiles = []; -}; diff --git a/privacy/tests/coverage.php b/privacy/tests/coverage.php deleted file mode 100644 index da0e4001f36..00000000000 --- a/privacy/tests/coverage.php +++ /dev/null @@ -1,49 +0,0 @@ -. - -defined('MOODLE_INTERNAL') || die(); - -/** - * Coverage information for the tool_dataprivacy plugin. - * - * @package core - * @category phpunit - * @copyright 2018 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -/** - * Coverage information for the tool_dataprivacy plugin. - * - * @copyright 2018 Andrew Nicols - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ -return new class extends phpunit_coverage_info { - /** @var array The list of folders relative to the plugin root o include in coverage generation. */ - protected $includelistfolders = [ - 'classes', - ]; - - /** @var array The list of files relative to the plugin root to include in coverage generation. */ - protected $includelistfiles = []; - - /** @var array The list of folders relative to the plugin root to exclude from coverage generation. */ - protected $excludelistfolders = [ - ]; - - /** @var array The list of files relative to the plugin root to exclude from coverage generation. */ - protected $excludelistfiles = []; -}; diff --git a/reportbuilder/tests/coverage.php b/reportbuilder/tests/coverage.php deleted file mode 100644 index 1948492a919..00000000000 --- a/reportbuilder/tests/coverage.php +++ /dev/null @@ -1,43 +0,0 @@ -. - -/** - * Coverage information for core_reportbuilder - * - * @package core_reportbuilder - * @copyright 2020 Paul Holden - * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later - */ - -declare(strict_types=1); - -defined('MOODLE_INTERNAL') || die(); - -return new class extends phpunit_coverage_info { - /** @var array The list of folders relative to the plugin root to include in coverage generation. */ - protected $includelistfolders = [ - 'classes', - ]; - - /** @var array The list of files relative to the plugin root to include in coverage generation. */ - protected $includelistfiles = []; - - /** @var array The list of folders relative to the plugin root to exclude in coverage generation. */ - protected $excludelistfolders = []; - - /** @var array The list of files relative to the plugin root to exclude in coverage generation. */ - protected $excludelistfiles = []; -};