Namespaces broken in 4.4 unit tests?

Namespaces broken in 4.4 unit tests?

per Howard Miller -
Nombre de respostes: 3
Imatge Core developers Imatge Documentation writers Imatge Particularly helpful Moodlers Imatge Peer reviewers Imatge 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?

Mitjana de qualificacions: -
En resposta a Howard Miller

Re: Namespaces broken in 4.4 unit tests?

per Leon Stringer -
Imatge Core developers Imatge 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?

En resposta a Leon Stringer

Re: Namespaces broken in 4.4 unit tests?

per Howard Miller -
Imatge Core developers Imatge Documentation writers Imatge Particularly helpful Moodlers Imatge Peer reviewers Imatge Plugin developers
I'm not sure... my first thought was that this is something to do with caching. I've been caught out before with the autoloader and caches but I'm not sure how this works with phpunit.
En resposta a Howard Miller

Re: Namespaces broken in 4.4 unit tests?

per Howard Miller -
Imatge Core developers Imatge Documentation writers Imatge Particularly helpful Moodlers Imatge Peer reviewers Imatge 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.