Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Test Autoloading Cleanup #3812

Merged
merged 2 commits into from
Oct 27, 2022
Merged

Test Autoloading Cleanup #3812

merged 2 commits into from
Oct 27, 2022

Conversation

splitbrain
Copy link
Collaborator

Namespacing and autoloading for our tests was a bit messed up. Some classes used the wrong tests namespace instead of the proper dokuwiki\test namespace. Our autoloader did not correctly map the namespace to _test\tests either. This all didn't matter much as long as no test wanted to inherit from or use a sibling test - a problem I encountered while working on #3810. The fix suggested there in 12ebce9 however was too shortsighted and does not work as intended.

This PR fixes the autoloading properly and updates the namespaces for those tests that already use a PSR4 style naming. Others will need renaming later on.

This replaces my attempt in 12ebce9

The canonical namespace for DokuWiki core tests is dokuwiki/test/ and
this is mapped to _test/tests now in the autoloader.

This means the majority of tests is in the dokuwiki/test/inc namespace.

Mockfiles are located at _test/mock and have the namespace
dokuwiki/test/mock - if that's good or bad is debatable. I simply kept
it as it always has been. But there might be an argument for having mock
objects closer to the tests that use them (eg. right next to the test
files).
This adds the test namespace to those test classes that are already in
PSR4 format.
@splitbrain
Copy link
Collaborator Author

BTW. IntelliJ Idea can be set up to be aware of different Namespaces using the Modules Settings (can be opened with F4 when focused on the file tree). You can mark folders as Sources or Tests, then use the pen icon next to it on the right to configure the namespace associated with it.

Here's an example from my setup:

2022-10-19-155335_1024x815_scrot

This should be added to the docs at https://www.dokuwiki.org/devel:unittesting when this is merged.

@splitbrain splitbrain merged commit a6afc21 into master Oct 27, 2022
@splitbrain splitbrain deleted the testns branch October 27, 2022 12:56
@splitbrain
Copy link
Collaborator Author

Hmm. Having merged this, I wanted to update the documentation and discovered that I'm still not happy with how this works.

Currently (with this patch applied) dokuwiki\File\PageResolver is tested in dokuwiki\test\inc\File\PageResolver. But I would prefer it to be dokuwiki\test\File\PageResolver. This will require a bit more reshuffling, but I think it makes it a bit more logical. Follow up PR will follow.

splitbrain added a commit that referenced this pull request Oct 27, 2022
Having "inc" in the namespace is awkward. Instead the test class
namespaces now correspond to their real class namespaces.

With further refactorings we should get rid of most of the stuff in
tests/inc

this is a continuation of #3812
@Klap-in
Copy link
Collaborator

Klap-in commented Oct 27, 2022

Nice that you made it more uniform. I did not realize that the dev plugin could add the needed boilerplate quickly, thanks for the docs update as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants