Namespaces broken in 4.4 unit tests?

Namespaces broken in 4.4 unit tests?

by Howard Miller -
Number of replies: 3
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of 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?

Average of ratings: -
In reply to Howard Miller

Re: Namespaces broken in 4.4 unit tests?

by Leon Stringer -
Picture of Core developers Picture of 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?

Average of ratings: Useful (1)
In reply to Leon Stringer

Re: Namespaces broken in 4.4 unit tests?

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of 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.
In reply to Howard Miller

Re: Namespaces broken in 4.4 unit tests?

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