Skip to content

Commit

Permalink
fix: Avoids error for unsupported events. (#227)
Browse files Browse the repository at this point in the history
  • Loading branch information
ryasmi authored Aug 16, 2018
1 parent 62a5479 commit e374da7
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/transformer/handler.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,16 @@ function handler(array $config, array $events) {
$eventobj = (object) $event;
try {
$eventname = $eventobj->eventname;
$eventfunctionname = $eventfunctionmap[$eventname];
$eventfunction = '\src\transformer\events\\' . $eventfunctionname;
$eventconfig = array_merge([
'event_function' => $eventfunction,
], $config);
$eventstatements = $eventfunction($eventconfig, $eventobj);
if (isset($eventfunctionmap[$eventname])) {
$eventfunctionname = $eventfunctionmap[$eventname];
$eventfunction = '\src\transformer\events\\' . $eventfunctionname;
$eventconfig = array_merge([
'event_function' => $eventfunction,
], $config);
$eventstatements = $eventfunction($eventconfig, $eventobj);
} else {
$eventstatements = [];
}
$transformedevent = [
'eventid' => $eventobj->id,
'statements' => $eventstatements,
Expand Down
1 change: 1 addition & 0 deletions tests/core/unknown_event/test/data.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
4 changes: 4 additions & 0 deletions tests/core/unknown_event/test/event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"id": 1,
"eventname": "unknown_event"
}
1 change: 1 addition & 0 deletions tests/core/unknown_event/test/statements.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
24 changes: 24 additions & 0 deletions tests/core/unknown_event/test/test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?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/>.

namespace tests\core\unknown_event\test;
defined('MOODLE_INTERNAL') || die();

class test extends \tests\xapi_test_case {
protected function get_test_dir() {
return __DIR__;
}
}

0 comments on commit e374da7

Please sign in to comment.