-
Bug
-
Resolution: Fixed
-
Minor
-
5.0
-
MOODLE_500_STABLE
-
MOODLE_500_STABLE
-
- Covered by automated tests (PHPUnit)
-
See the following method parameter added in MDL-82977
public function create_provider_instance(
|
...
|
?array $config = null,
|
): provider {
|
The problem is you cannot omit the parameter (despite the contract stating it's optional) because if null value is passed we get the following error:
There were 4 errors:
|
|
1) aiprovider_openai\provider_test::test_get_action_list
|
TypeError: Cannot assign null to property core_ai\provider::$config of type array
|
|
/mnt/export/moodle/master/src/ai/classes/provider.php:61
|
/mnt/export/moodle/master/src/ai/classes/manager.php:380
|
/mnt/export/moodle/master/src/ai/provider/openai/tests/provider_test.php:45
|
We also cannot pass an empty array, because if we do that they we get the same error again:
There were 4 errors:
|
|
1) aiprovider_openai\provider_test::test_get_action_list
|
TypeError: Cannot assign null to property core_ai\provider::$config of type array
|
|
/mnt/export/moodle/master/src/ai/classes/provider.php:61
|
/mnt/export/moodle/master/src/ai/classes/manager.php:380
|
/mnt/export/moodle/master/src/ai/provider/openai/tests/provider_test.php:45
|
The problem is this line of the change because subsequent methods in the callstack always assume that value is a JSON encoded array. Fix that, tighten up the contract and remove this element of surprise for developers
I suspect this is why the unit tests that is never asserted. Looks like a code smell just to workaround this bug
Found this while writing some unit tests for an AI provider during project week
- is a regression caused by
-
MDL-82977 AI: Provider instances
-
- Closed
-