Namespaces broken in 4.4 unit tests?

Namespaces broken in 4.4 unit tests?

oleh Howard Miller -
Jumlah balasan: 3
Gambar dari Core developers Gambar dari Documentation writers Gambar dari Particularly helpful Moodlers Gambar dari Peer reviewers Gambar dari 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?

Rata-rata penilaian: -
Sebagai balasan Howard Miller

Re: Namespaces broken in 4.4 unit tests?

oleh Leon Stringer -
Gambar dari Core developers Gambar dari 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?

Rata-rata penilaian:Useful (1)
Sebagai balasan Leon Stringer

Re: Namespaces broken in 4.4 unit tests?

oleh Howard Miller -
Gambar dari Core developers Gambar dari Documentation writers Gambar dari Particularly helpful Moodlers Gambar dari Peer reviewers Gambar dari 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.
Sebagai balasan Howard Miller

Re: Namespaces broken in 4.4 unit tests?

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