This is a followup of
85f47ba, where we were relaxing
the (new since phpunit 7.x) strict (===) isEqual()
comparison for strings. Copying the explanations for
easier understanding.
Link: https://github.com/sebastianbergmann/phpunit/issues/3185
Solution here is one of:
a) Return to the previous situation, making the comparison
softer. That can achieved by forcing different types, so
float == string works.
b) Changing APIs (both forms and database return strings) to
perform some conversion to floats. That would make float
comparison (with floats or strings) to work too.
The patch here follows the a) approach. Changing all the internals
for proper float handling sounds excesive when it has been working
perfectly since ever. So we went the easier route, just getting
rid of the new === comparisons when needed by changing expectation
types to float.
$record->id = '1';
$record->course = '1';
$record->oneint = null;
- $record->onenum = '1.00';
+ $record->onenum = 1.0;
$record->onechar = 'a';
$record->onetext = 'aaa';
$state = $states[$this->usageids[0]][$this->allslots[0]];
$this->assertEquals((object) array(
'questionid' => $this->sa->id,
- 'maxmark' => '5.0000000',
+ 'maxmark' => 5.0,
'sequencenumber' => 2,
'state' => (string) question_state::$gradedright,
), $state);
$state = $states[$this->usageids[0]][$this->allslots[1]];
$this->assertEquals((object) array(
'questionid' => $this->essay->id,
- 'maxmark' => '10.0000000',
+ 'maxmark' => 10.0,
'sequencenumber' => 2,
'state' => (string) question_state::$needsgrading,
), $state);
$state = $states[$this->usageids[1]][$this->allslots[0]];
$this->assertEquals((object) array(
'questionid' => $this->sa->id,
- 'maxmark' => '5.0000000',
+ 'maxmark' => 5.0,
'sequencenumber' => 2,
'state' => (string) question_state::$gradedwrong,
), $state);
$state = $states[$this->usageids[1]][$this->allslots[1]];
$this->assertEquals((object) array(
'questionid' => $this->essay->id,
- 'maxmark' => '10.0000000',
+ 'maxmark' => 10.0,
'sequencenumber' => 1,
'state' => (string) question_state::$gaveup,
), $state);
$state = $states[$this->usageids[0]][$this->allslots[0]];
$this->assertEquals((object) array(
'questionid' => $this->sa->id,
- 'maxmark' => '5.0000000',
+ 'maxmark' => 5.0,
'sequencenumber' => 2,
'state' => (string) question_state::$gradedright,
), $state);
$state = $states[$this->usageids[0]][$this->allslots[1]];
$this->assertEquals((object) array(
'questionid' => $this->essay->id,
- 'maxmark' => '10.0000000',
+ 'maxmark' => 10.0,
'sequencenumber' => 2,
'state' => (string) question_state::$needsgrading,
), $state);
$state = $states[$this->usageids[1]][$this->allslots[0]];
$this->assertEquals((object) array(
'questionid' => $this->sa->id,
- 'maxmark' => '5.0000000',
+ 'maxmark' => 5.0,
'sequencenumber' => 2,
'state' => (string) question_state::$gradedwrong,
), $state);
$state = $states[$this->usageids[1]][$this->allslots[1]];
$this->assertEquals((object) array(
'questionid' => $this->essay->id,
- 'maxmark' => '10.0000000',
+ 'maxmark' => 10.0,
'sequencenumber' => 1,
'state' => (string) question_state::$gaveup,
), $state);
$q->options->answers[0]->question = '3379';
$q->options->answers[0]->answer = '{a} + {b}';
$q->options->answers[0]->answerformat = '0';
- $q->options->answers[0]->fraction = '1.0000000';
+ $q->options->answers[0]->fraction = 1.0;
$q->options->answers[0]->feedback = '';
$q->options->answers[0]->feedbackformat = '1';
$q->options->answers[0]->tolerance = '0.01';
$q->options->units = array();
$q->options->unitgradingtype = '0';
- $q->options->unitpenalty = '0.1000000';
+ $q->options->unitpenalty = 0.1;
$q->options->showunits = '3';
$q->options->unitsleft = '0';
$q->options->answers = array();
$q->options->answers[0] = new stdClass();
$q->options->answers[0]->answer = '3.14';
- $q->options->answers[0]->fraction = '1.0000000';
+ $q->options->answers[0]->fraction = 1.0;
$q->options->answers[0]->feedback = 'Very good.';
$q->options->answers[0]->feedbackformat = FORMAT_HTML;
$q->options->answers[0]->tolerance = '0';
$q->options->answers[1] = new stdClass();
$q->options->answers[1]->answer = '3.142';
- $q->options->answers[1]->fraction = '0.0000000';
+ $q->options->answers[1]->fraction = 0.0;
$q->options->answers[1]->feedback = 'Too accurate.';
$q->options->answers[1]->feedbackformat = FORMAT_HTML;
$q->options->answers[1]->tolerance = '0';
$q->options->answers[2] = new stdClass();
$q->options->answers[2]->answer = '3.1';
- $q->options->answers[2]->fraction = '0.0000000';
+ $q->options->answers[2]->fraction = 0.0;
$q->options->answers[2]->feedback = 'Not accurate enough.';
$q->options->answers[2]->feedbackformat = FORMAT_HTML;
$q->options->answers[2]->tolerance = '0';
$q->options->answers[3] = new stdClass();
$q->options->answers[3]->answer = '3';
$q->options->answers[3]->answerformat = '0';
- $q->options->answers[3]->fraction = '0.0000000';
+ $q->options->answers[3]->fraction = 0.0;
$q->options->answers[3]->feedback = 'Not accurate enough.';
$q->options->answers[3]->feedbackformat = FORMAT_HTML;
$q->options->answers[3]->tolerance = '0';
$q->options->answers[4] = new stdClass();
$q->options->answers[4]->answer = '*';
$q->options->answers[4]->answerformat = '0';
- $q->options->answers[4]->fraction = '0.0000000';
+ $q->options->answers[4]->fraction = 0.0;
$q->options->answers[4]->feedback = 'Completely wrong.';
$q->options->answers[4]->feedbackformat = FORMAT_HTML;
$q->options->answers[4]->tolerance = '0';
$q->options->units = array();
$q->options->unitgradingtype = '0';
- $q->options->unitpenalty = '0.1000000';
+ $q->options->unitpenalty = 0.1;
$q->options->showunits = '3';
$q->options->unitsleft = '0';
$q->options->answers = array();
$q->options->answers[0] = new stdClass();
$q->options->answers[0]->answer = 'True';
- $q->options->answers[0]->fraction = '1.0000000';
+ $q->options->answers[0]->fraction = 1.0;
$q->options->answers[0]->feedback = 'This is the right answer.';
$q->options->answers[0]->feedbackformat = FORMAT_HTML;
$q->options->answers[1] = new stdClass();
$q->options->answers[1]->answer = 'False';
- $q->options->answers[1]->fraction = '0.0000000';
+ $q->options->answers[1]->fraction = 0.0;
$q->options->answers[1]->feedback = 'This is the wrong answer.';
$q->options->answers[1]->feedbackformat = FORMAT_HTML;