#34161 closed enhancement (fixed)
PhpMailer mock decorator methods
Reported by: | welcher | Owned by: | boonebgorges |
---|---|---|---|
Milestone: | 4.5 | Priority: | normal |
Severity: | normal | Version: | |
Component: | Build/Test Tools | Keywords: | has-patch dev-feedback has-unit-tests |
Focuses: | Cc: |
Description (last modified by )
When writing unit tests for items that use the Mock PHPMailer working with the object is tedious. I am proposing some decorator methods to allow better clarity and access to the various items in the mock_sent
array.
The attached patch includes the new methods and updates a test to demonstrate usage as well as the enhanced readability the new methods provide.
Attachments (3)
Change History (15)
This ticket was mentioned in Slack in #core by welcher. View the logs.
9 years ago
#4
@
9 years ago
@DrewAPicture thanks for the notes.
I'll explicitly add the access modifiers in for sure. I can remove the helper methods that call the get_address
method if that makes more sense from a code bloat point of view as well.
As for the tests, I only updated one of the Unit Tests in the tests/mail.php
file so there are definitely more tests in the that file and core in general that would benefit from these changes. I'm happy to update all the calls ( and probably should anyway ) to get a better sense of the full scope.
#5
@
9 years ago
Updated patch with the following changes:
- Removing the helper methods in favour of the generic
get_address
to keep the code additions to the minimum. - Updated all tests that where accessing
$GLOBALS['phpmailer']
to now use this new approach and all tests are passing.
This ticket was mentioned in Slack in #core by welcher. View the logs.
9 years ago
#10
@
9 years ago
Thanks for the patch, @welcher. This is definitely more sane that the current method of reaching into the global. I think we can simplify somewhat; given the elegance of syntax like $mailer->get_sent()->to
etc, why would we ever want get_sent()
or get_recipient()
to return an array rather than an object?
This approach definitely seems a lot cleaner, though that's a lot of code to make 10 assertions shorter.
Can you also add access modifiers to the new methods? And I'm not terribly concerned about the docs formatting in tests as long as it gets the message across.