-
-
Notifications
You must be signed in to change notification settings - Fork 825
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
tests/events/*.php - Enforce general compliance with hook/event signatures #21615
tests/events/*.php - Enforce general compliance with hook/event signatures #21615
Conversation
(Standard links)
|
a5a06d7
to
650646e
Compare
f82156e
to
1348d06
Compare
So you know I hate this because it locks in us passing a legacy paramter ( I really think that we should be giving really clear release notes & messaging about it in the release blog & stopping the bleeding on However, it seems like it's sucking the air out of everything so I'll merge it. |
(1) I think you're misreading the intent. This doesn't lock us in. It's just about clarity. I want clarity that the changes we think we make are the changes that we actually make. That is not a given when working with (2) It sounds like you interpreted the test as requiring that 'groupName' => [
// This field is generally deprecated. Historically, this was tied to various option-groups (`msg_*`),
// but it also seems to have been used with a few long-form English names.
'regex' => '/^(msg_[a-zA-Z_]+|Scheduled Reminder Sender|Activity Email Sender|Report Email Sender|Mailing Event Welcome|CRM_Core_Config_MailerTest)$/',
'type' => 'string',
'for' => ['messageTemplate', 'singleEmail'],
], These rules are only consulted if the field is actually supplied. So breaking out what that means...
I get confused by your assertion that this is somehow locking us into supporting Re-reading, there is one small patch we may want: - 'type' => 'string',
+ 'type' => 'string|NULL', i.e. Right now, it might complain if the field be both present and null (ie |
@totten ok - so we CAN rip out |
Overview
Introduce a suite of tests (
tests/events/*.php
) which enforce general compliance with hook-signatures. Improve predictability/reliability of hook-data. Add a couple examples.(This is re-spin of #20438. The original PR attempted to identify quirks in
hook_civicrm_pre
as well ashook_civicrm_post
, and the list of quirks was too long. So this targets a more modest hook, which is less pervasive - but still a bit quirky.)Before
While some hooks have thoughtful test-coverage, many have no test-coverage or inadequate coverage. Techniques for testing hooks are adhoc and focused on individual use-cases. It is difficult to write a test that covers the range of ways in which a hook executes.
Consider
hook_civicrm_alterMailParams
. There is one test in CiviMail which asserts that the hook fires (CRM_Mailing_MailingSystemTest
). But does the hook have sensible content? If an extension-author wants to use the hook, what fields will be available? Under what conditions? Sure, you could updateMailingSystemTest
to describe the flavor of the hook emitted by CiviMail -- but what about the flavors of the hook fromActionSchedule
orMessageTemplates
? They're different. For consumers of the hook, we should be presenting a coherent contract -- and we don't have a way to test conformance of those various callers.After
One may write a general test which will be used any time a hook fires (at least, any time it fires within PHPUnit). For example, consider this draft of
tests/events/hook_civicrm_alterMailParams.evch.php
:This leverages all the existing scenarios in the core test-suites and ensures that the hook always presents data in the expected format (regardless of when or how it's fired). If
alterMailParams
ever fires with an undocumented$context
, or if something neglects to pass in the email 'subject', then it will raise an error.Comments
While working through the example of
alterMailParams
, I discovered some interesting things, like:sendTemplate()
, this hook will actually fire twice:$context==messageTemplate
. Some key parameters (html
,body
,subject
) are not populated at this time.$context==singleEmail
. This is the more complete rendering. (But it fires too late to influence some content.)groupName
- This is a constant value'Scheduled Reminder Sender'
. This is very different from how message-templates traditionally used thevalueName
/groupName
. (Note thatvalueName
is not used, andgroupName
is not an option-group, and it doesn't following the naming-convention of the old option-groups.)entity
andentity_id
: This is the target record which was matched by date-filter.Of course, when you discover these quirks, you might want to go on safari and do something with them - eg document them in https://docs.civicrm.org/dev/en/latest/hooks/hook_civicrm_alterMailParams/ or transition the behavior to something else. But... I'll take it as progress that (1) we're able to identify these existing quirks and (2) we'll get an automated headsup if something tries to introduce more quirks.