Closed ewallah closed 4 years ago
Thanks for checking.
Can you check if it's passing the test if you change the line like below:
'url' => new external_value(PARAM_URL, 'URL', VALUE_OPTIONAL, ''),
Sorry, but this does not help.
Moodle simply does not like optional values: line 712 of /lib/externallib.php is throwing an exception for all optional values:
if ($CFG->debugdeveloper) {
foreach ($keys as $key => $value) {
if ($value instanceof external_value) {
if ($value->required == VALUE_OPTIONAL) {
debugging('External function parameters: invalid OPTIONAL value specified.', DEBUG_DEVELOPER);
break;
}
}
}
}
Could this be security related?
Strange I think it's only a notice. The documentation doesn't advise to not use VALUE_OPTIONAL
https://docs.moodle.org/dev/Adding_a_web_service_to_a_plugin#Required.2C_Optional_or_Default_value
The note in your link explains everything: Because some web service protocols are strict about the number and types of arguments - it is not possible to specify an optional parameter as one of the top-most parameters for a function.
The cool sample get_biscuit_parameters() provides a solution.
Thanks for checking the Moodle webservice page. I will implement this in the next version.
@ewallah Can you check if you still see this problem when running phpunit? Should be solved now.
#vendor/bin/phpunit --colors "core_externallib_testcase" lib/tests/externallib_test.php
Moodle 3.8.3+ (Build: 20200711), a6227d56752c3af728f09dc863e50062f1bac773
Php: 7.3.20.1.18.04.1.1, pgsql: 10.12 (Ubuntu 10.12-0ubuntu0.18.04.1), OS: Linux 4.15.0-109-generic x86_64
PHPUnit 7.5.20 by Sebastian Bergmann and contributors.
............................................................... 63 / 649 ( 9%)
............................................................... 126 / 649 ( 19%)
............................................................... 189 / 649 ( 29%)
............................................................... 252 / 649 ( 38%)
............................................................... 315 / 649 ( 48%)
............................................................... 378 / 649 ( 58%)
............................................................... 441 / 649 ( 67%)
............................................................... 504 / 649 ( 77%)
............................................................... 567 / 649 ( 87%)
............................................................... 630 / 649 ( 97%)
................... 649 / 649 (100%)
Time: 6.71 seconds, Memory: 103.00 MB
OK (649 tests, 3875 assertions)
Fixed!
👌thanks for checking
When running phpunit tests 1 error is detected:
When I modify the externallib.php file and change the url from optional to required,
the error is gone, and the block continue to work as expected.
Any reason why you need an optional external value?