moodle-logstore_xapi icon indicating copy to clipboard operation
moodle-logstore_xapi copied to clipboard

Test data represents numbers as numbers but Moodle DB returns them as strings

Open garemoko opened this issue 6 years ago • 2 comments

See https://github.com/xAPI-vle/moodle-logstore_xapi/pull/388 for an example.

All of our test data has numbers in the json as numbers, however when pulling the data from the Moodle database the numbers come in as strings. This causes the issue where an event may pass tests when expecting a number, but then throw errors relating to the wrong type being expected in real life.

garemoko avatar Jan 07 '19 12:01 garemoko

The issue is in the test repository: https://github.com/xAPI-vle/moodle-logstore_xapi/blob/master/src/transformer/repos/TestRepository.php#L43

if ($record->$key === $value) {

I think should be:

if ($record->$key === intval($value)) {

While we're in there, there seem to be logic issues around multiple query parameters. The Moodle function will only return matches where all the query parameters match, however it looks to me that the test repo will return records where ANY of the query parameters match:

foreach ($query as $key => $value) {
    if ($record->$key === $value) {
        $matchingrecords[] = (object) $record;
    }
}

garemoko avatar Jan 07 '19 12:01 garemoko

Interesting, I think you might be right with both of those. I believe when I started making the test data I used numbers instead of strings because I was creating the test data as I saw it from snapshots of the database for particular events.

ryasmi avatar Jan 08 '19 09:01 ryasmi