Helpers\IsUnitTestTrait: bug fix - allow for custom test classes passed as FQN #2267
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
While looking at an old PR (#1960), I realized that custom test classes passed as FQN were not handled correctly by the trait. This code was not adjusted in that PR, just moved, so this bug has existed for a while.
The problem was in this code snippet:
After the merge of the custom classes, the
$known_test_classes
array is instring
=>bool
format, so theforeach()
loop is absolutely not having the intended effect. The only thing it does, is change the boolean value to strings...I also noticed that the array merge was being done every single time the
is_test_class()
method was being called. We can make that a bit more efficient as it will be rare that the list of custom tests classes changes during a run.So, I have made the following changes:
get_all_test_classes()
method which will handle the cleaning of the custom names and the merge. This new class uses two new properties$added_custom_test_classes
and$all_test_classes
to prevent having to do the same merge over and over again.$known_test_classes
property has now been madeprivate
.$known_test_classes
.$custom_test_classes
will bestring[]
and hasn't been "flipped" yet (keys/values reversed).Includes additional unit tests.