Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

BUG: PHPUnit test is failing in Moodle 3.11 and 4.0 #32

Closed
michael-milette opened this issue Jun 7, 2022 · 4 comments
Closed

BUG: PHPUnit test is failing in Moodle 3.11 and 4.0 #32

michael-milette opened this issue Jun 7, 2022 · 4 comments
Labels

Comments

@michael-milette
Copy link

When I run the unit test on multilang2, I get the following error:

Class 'filter_test' could not be found in '/filter/multilang2/tests/filter_test.php'.

I suspect this is due to changes in PHPUnit 9.5.

Any chance you could fix this please?

Best regards,

Michael

@iarenaza
Copy link
Owner

iarenaza commented Jun 9, 2022

Humm, I just run the tests in both 3.11 (version 2021051707.04) and 4.0 (version 2022041901.04) with the following invocation:

[moodle-311] $ vendor/bin/phpunit --filter filter_multilang2
Moodle 3.11.7+ (Build: 20220603), 2fe2cd8eabfd6148dca541b394cc60134176d7ce
Php: 7.4.28, pgsql: 13.7 (Debian 13.7-0+deb11u1), OS: Linux 5.18.2 x86_64
PHPUnit 9.5.13 by Sebastian Bergmann and contributors.

.....                                                               5 / 5 (100%)

Time: 00:00.338, Memory: 277.00 MB

OK (5 tests, 7 assertions)
[moodle-311] $ cd ../moodle-400/
[moodle-400] $ vendor/bin/phpunit --filter filter_multilang2
Moodle 4.0.1+ (Build: 20220603)
Php: 7.4.28, pgsql: 13.7 (Debian 13.7-0+deb11u1), OS: Linux 5.18.2 x86_64
PHPUnit 9.5.13 by Sebastian Bergmann and contributors.

.....                                                               5 / 5 (100%)

Time: 00:00.364, Memory: 294.00 MB

OK (5 tests, 7 assertions)
[moodle-400] $

And as you can see, it seems to be using PHPUnit 9.5, and executing the tests successfully in both cases. So I am unable to reproduce the issue locally. And I don't know what else to do to try to reproduce it. Does your output show the same tools versions as mine (PHP version aside, as depending on your environment it may be different). Althoug that may be it, are you using a more recent PHP version? Like 8.x?

@michael-milette
Copy link
Author

Hi @iarenaza

I am using PHPUnit 9.5 with PHP 7.4.25 and the latest release of moodle-local_codechecker. I tried the command line you used and got similar results to yours. I think it is a difference in the command line that I use:

vendor/bin/phpunit filter/multilang2/tests/filter_test.php

The result is:

Moodle 4.0.1+ (Build: 20220603), 6bafbcc92d6a7feb3e57d08eec4a8e10a1864196
Php: 7.4.25, mariadb: 10.4.6
Class 'filter_test' could not be found in '/filter/multilang2/tests/filter_test.php'.

The problem is that the PHPUnit requirements for class and file naming changed starting with Moodle 3.11 and up. For more information, see https://docs.moodle.org/dev/PHPUnit_integration#Class_and_file_naming_rules

On a side note, in order to avoid a code precheck phpcs warnings on Moodle.org, I recommend you also look into @Covers. See:
https://phpunit.readthedocs.io/en/9.5/annotations.html#covers

Hope you find this information helpful.

Best regards,

Michael Milette

@michael-milette
Copy link
Author

Hi @iarenaza

FYI: Without the correction, you will get the following warning messages in the section PHP coding style problems in the precheck next time you upload try to load the plugin to Moodle.org. Note: This is just a simulation of the warning messages (I substituted filtercodes for multilang2 in the messages):

PHPUnit testcase name "filter_multilang2_testcase" does not match file name "filter_test".

PHPUnit class "filter_multilang2_testcase" does not have any namespace. It is recommended to add it to the "filter_multilang2" namespace, using more levels if needed, in order to match the code being tested.

Test method test_filter_multilang2() is missing any coverage information, own or at class level.

I had similar issues with my FilterCodes plugin whose test file was configured similar to yours. If you are interested, visit https://github.com/michael-milette/moodle-filter_filtercodes/blob/master/tests/filter_test.php to see how I resolved it.

The version of FilterCodes on Moodle.org still generated one warning but that is because it does not include the @Covers which is included in the version on GitHub.

I am a big fan of your plugin and just want to help you out. Thank you for all your efforts.

Michael

lucaboesch added a commit to lucaboesch/moodle-filter_multilang2 that referenced this issue Dec 4, 2022
lucaboesch added a commit to lucaboesch/moodle-filter_multilang2 that referenced this issue Dec 4, 2022
lucaboesch added a commit to lucaboesch/moodle-filter_multilang2 that referenced this issue Dec 4, 2022
lucaboesch added a commit to lucaboesch/moodle-filter_multilang2 that referenced this issue Dec 4, 2022
lucaboesch added a commit to lucaboesch/moodle-filter_multilang2 that referenced this issue Dec 4, 2022
lucaboesch added a commit to lucaboesch/moodle-filter_multilang2 that referenced this issue Dec 4, 2022
@iarenaza
Copy link
Owner

Thanks a lot @lucaboesch and @michael-milette for your help fixing this issue!

@iarenaza iarenaza added the bug label Oct 26, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants