Namespaces broken in 4.4 unit tests?

Namespaces broken in 4.4 unit tests?

Howard Miller -
Кількість відповідей: 3
Фото Core developers Фото Documentation writers Фото Particularly helpful Moodlers Фото Peer reviewers Фото Plugin developers

Headline - used to work in 4.1, but doesn't in 4.4

I followed the instructions for writing tests here - https://moodledev.io/docs/4.4/apis/subsystems/external/testing

In 4.1 it worked. The external class (get_fruit in the docs) was found. In (https://docs.moodle.org/dev/Writing_PHPUnit_tests) it says "grand summary = 100% the same rules that are applied to **/classes directories", so all that adds up.

However, in 4.4, it is no longer found. Even explicitly specifying the full class name (local_myplugin\external\get_fruit) does not find the class - so something seems to have changed. 

The actual error is...

Error: Class "local_myplugin\external\my_external_class" not found

...that class definitely exists, and (as mentioned) it all worked in 4.1.

Any ideas?

У відповідь на Howard Miller

Re: Namespaces broken in 4.4 unit tests?

Leon Stringer -
Фото Core developers Фото Particularly helpful Moodlers

It's not exactly the same but it's not an MUC issue similar to MDL-68122 that's just occurring because it's a new environment?

У відповідь на Howard Miller

Re: Namespaces broken in 4.4 unit tests?

Howard Miller -
Фото Core developers Фото Documentation writers Фото Particularly helpful Moodlers Фото Peer reviewers Фото Plugin developers
I'm guilty of starting a new thread for something that turned out to be related, https://moodle.org/mod/forum/discuss.php?d=458289

I'm not sure if it's the best way or even only way, but explicitly providing 'use' statements for needed classes seems to solve the problem.

Even less sure, but 'require_once' in tests may be a bit risky. Again, try some other way.