-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.php
82 lines (69 loc) · 2.83 KB
/
lib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Lib functions for local_behatcoverage.
*
* @package local_behatcoverage
* @copyright 2023 Justus Dieckmann WWU
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use SebastianBergmann\CodeCoverage\CodeCoverage;
use SebastianBergmann\CodeCoverage\Report\PHP;
/**
* Function that starts
*/
function local_behatcoverage_after_config() {
if ($plugintocheck = 'block_qrcode') {
try {
local_behatcoverage_start_coverage($plugintocheck);
} catch (Exception $e) {
echo $e->getMessage();
}
}
}
function local_behatcoverage_start_coverage($plugintocheck) {
global $CFG;
require $CFG->dirroot . '/vendor/autoload.php';
$plugininfo = core_plugin_manager::instance()->get_plugin_info($plugintocheck);
$filter = new \SebastianBergmann\CodeCoverage\Filter();
$filter->includeDirectory($plugininfo->rootdir);
$filter->excludeDirectory($plugininfo->rootdir . '/lang/');
$filter->excludeDirectory($plugininfo->rootdir . '/tests/', '_test.php');
$filter->excludeDirectory($plugininfo->rootdir . '/thirdparty/');
$driver = (new \SebastianBergmann\CodeCoverage\Driver\Selector)->forLineCoverage($filter);
$codecoverage = new CodeCoverage($driver, $filter);
$codecoverage->includeUncoveredFiles();
core_shutdown_manager::register_function('local_behatcoverage_shutdown', [$codecoverage]);
$codecoverage->start('behat');
}
function local_behatcoverage_shutdown(CodeCoverage $codecoverage) {
global $CFG;
file_put_contents($CFG->dataroot . '/behatlogdata.log', json_encode([
'rootdir' => $CFG->dirroot,
'dataroot' => $CFG->dataroot,
'wwwroot' => $CFG->wwwroot,
'request_uri' => $_SERVER['REQUEST_URI'] ?? null,
'scriptname' => $_SERVER['SCRIPT_NAME'] ?? null,
'sapiname' => php_sapi_name()
]) . "\n", FILE_APPEND);
$codecoverage->stop();
if (file_exists($CFG->dataroot . '/behat.cov')) {
$past = include $CFG->dataroot . '/behat.cov';
$codecoverage->merge($past);
}
$php = new PHP();
$php->process($codecoverage, $CFG->dataroot . '/behat.cov');
}