Added full phpunit coverage for classes in: cli and event

This commit is contained in:
Daniel Thee Roperto
2016-09-19 20:05:21 +10:00
parent 2959719c58
commit edbbc2dd83
15 changed files with 265 additions and 40 deletions

View File

@@ -19,10 +19,6 @@ namespace auth_outage\cli;
use core\session\manager;
use InvalidArgumentException;
defined('MOODLE_INTERNAL') || die();
require_once($CFG->libdir . '/clilib.php');
/**
* Outage CLI base class.
*
@@ -48,6 +44,9 @@ abstract class clibase {
* @throws cliexception
*/
public function __construct(array $options = null) {
global $CFG;
require_once($CFG->libdir . '/clilib.php');
$this->becomeadmin();
if (is_null($options)) {

View File

@@ -27,4 +27,13 @@ use Exception;
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class cliexception extends Exception {
/**
* cliexception constructor.
* @param string $message An explanation of the exception.
* @param int $code Exit code to be used.
* @param Exception|null $previous Another exception as reference.
*/
public function __construct($message, $code = 1, Exception $previous = null) {
parent::__construct('*ERROR* ' . $message, $code, $previous = null);
}
}

View File

@@ -19,8 +19,6 @@ namespace auth_outage\cli;
use auth_outage\models\outage;
use auth_outage\outagedb;
defined('MOODLE_INTERNAL') || die();
/**
* Outage CLI to create outage.
*

View File

@@ -19,8 +19,6 @@ namespace auth_outage\cli;
use auth_outage\models\outage;
use auth_outage\outagedb;
defined('MOODLE_INTERNAL') || die();
/**
* Outage CLI to finish an outage.
*

View File

@@ -19,8 +19,6 @@ namespace auth_outage\cli;
use auth_outage\models\outage;
use auth_outage\outagedb;
defined('MOODLE_INTERNAL') || die();
/**
* Outage CLI to wait for an outage to start.
*

View File

@@ -17,8 +17,7 @@
namespace auth_outage\event;
use core\event\base;
defined('MOODLE_INTERNAL') || die();
use moodle_url;
/**
* The auth_outage outage created class.
@@ -51,9 +50,9 @@ class outage_created extends base {
/**
* Returns relevant URL, override in subclasses.
* @return \moodle_url
* @return moodle_url
*/
public function get_url() {
return new \moodle_url('/auth/outage/list.php#auth_outage_id_' . $this->other['id']);
return new moodle_url('/auth/outage/list.php#auth_outage_id_' . $this->other['id']);
}
}

View File

@@ -18,8 +18,6 @@ namespace auth_outage\event;
use core\event\base;
defined('MOODLE_INTERNAL') || die();
/**
* The auth_outage outage deleted class.
*

View File

@@ -18,8 +18,6 @@ namespace auth_outage\event;
use core\event\base;
defined('MOODLE_INTERNAL') || die();
/**
* The auth_outage outage updated class.
*

View File

@@ -16,9 +16,7 @@
namespace auth_outage;
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
}
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . '/calendar/lib.php');
@@ -259,7 +257,7 @@ class outagedb {
if (is_null($time)) {
$time = time();
}
if (!is_int($time)) {
if (!is_int($time) && ($time <= 0)) {
throw new InvalidArgumentException('$time must be an int or null.');
}