PrintingFunctionsTrait: add tests#2716
Conversation
jrfnl
left a comment
There was a problem hiding this comment.
❌ I'm going to block this PR in its current state.
The is_printing_function() can't be considered properly tested unless the get_printing_functions() method is also tested.
So either dedicated tests for the get_printing_functions() method need to be added ahead of adding the tests for the is_printing_function() method; or the is_printing_function() tests need to be expanded to include covering what happens in get_printing_functions() (which I believe would be the wrong choice).
Adding tests only for is_printing_function() without having tests for get_printing_functions() is misleading and incomplete.
As a side-note regarding the test setup:
I understand what you are trying to do, but why did you choose this way to do it ?
I mean, why not just use PrintingFunctionsTrait; in the test class ? (which would also give the tests access to the private properties if needed).
|
Thanks for the review, Juliette.
Regarding testing
Regarding the test setup, I opted for the anonymous class approach to keep a clear separation between the test subject and the test class. Using I can see that the anonymous class approach adds boilerplate (and in the case of the |
I already said that this PR is blocked until tests for
Understood. Thanks for sharing your reasoning.
No strong preference. I totally see the value of the separation, but I can also see the value of the simpler approach for a simple trait like this if it would make testing the trait more straight-forward (less jumping through hoops to test what needs testing). I guess for a first set of tests, I would be pragmatic (whatever works), while when iterating on it after, I would consolidate to a standardized, consistent approach based on what we then know is needed. It's difficult to standardize/make things consistent if it's not clear yet what will be needed across the board. Hope that input helps. |
22e9b32 to
4a6fad5
Compare
|
I pushed a new commit adding tests for
I kept the anonymous class approach for now. We can revisit this decision in the future, as you suggested. I made a few choices regarding the test coverage for
I'm unsure if I opted for an overly simplistic approach, but I'm inclined to think it is enough for this somewhat simple method. What do you think? |
jrfnl
left a comment
There was a problem hiding this comment.
Just reviewed the new (second) commit. Hope this helps.
| * | ||
| * @return void | ||
| */ | ||
| public function testGetPrintingFunctionsContainsKnownFunction() { |
There was a problem hiding this comment.
May I suggest reworking this test a little to also check the "total count" of the expected return list ? Might also mean that the test name needs a little rethink.
Might also be worth it to have these assertions have $failure message parameter set as this test has multiple assertions in one test. (here and elsewhere)
|
Thanks for your review, @jrfnl. I added a new commit addressing the two suggestions you made. |
jrfnl
left a comment
There was a problem hiding this comment.
Left two nitpicks. nothing major.
Co-authored-by: Juliette <663378+jrfnl@users.noreply.github.com>
jrfnl
left a comment
There was a problem hiding this comment.
Okay, now the tests for get_*() are in place, I've gone back to reviewing the original commit for is_*() and I believe we are still missing one test - a test where the is_*() function returns true for a custom printing function.
Could you please add that @rodrigoprimo ?
I also changed the order of the data in the data provider.
|
That makes sense. Thanks for checking the other test class. I just pushed a commit implementing the change you suggested. |
jrfnl
left a comment
There was a problem hiding this comment.
Thanks for working on this @rodrigoprimo ! All good from me.
For whomever does the second review: please squash-merge.
|
@dingo-d and @GaryJones, Juliette approved this a while ago. Just checking if either of you is available to do the required second review of this PR? Thanks! |
Description
In preparation for supporting PHPCS 4.0, this PR adds unit tests for the
PrintingFunctionsTrait::is_printing_function()andPrintingFunctionsTrait::get_printing_functions()methods.Suggested changelog entry
N/A
Related issues/external references
Related to: #2272