-
-
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 - Allow optional runtime enforcement #28723
Conversation
🤖 Thank you for contributing to CiviCRM! ❤️ We will need to test and review this PR. 👷 Introduction for new contributors...
Quick links for reviewers...
|
This variant of hook_civicrm_links has multiple compliance issues. It raises so many red-flags that it makes the site unbrowseable and obscures any useful signal about the other hooks. Skip it until someone can take a full look.
ebe0603
to
d19c9bb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like this idea. I generally dislike being able to throw gibberish input in without being told it's gibberish. So I think it's a good step.
public static function assertNotEmpty($actual, string $message = ''): void { | ||
if (empty($actual)) { | ||
$comment = 'Value should not be empty.'; | ||
static::fail(trim("$message\n$comment")); | ||
} | ||
} | ||
|
||
public static function assertTrue($condition, string $message = ''): void { | ||
if ($condition !== TRUE) { | ||
$comment = 'Value should be TRUE.'; | ||
static::fail(trim("$message\n$comment")); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing these are just what we need right now and no more, but it feels weird to have assertNotEmpty and not assertEmpty; assertTrue and not assertFalse.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@artfulrobot Yup, exactly. I'm sure the vocabulary of assertions could be tuned-up more going forward.
Overview
The folder
tests/events/
(created by #21615) allows one to declare (and enforce) the signature for a hook. However, it only supports enforcement within unit-tests. This PR (optionally) expands enforcement to runtime.Before
Assert
).After
event_check
, then event-checks are also enforced at runtime. (Any non-conformant hook... on any page-request... will raise an exception.)Assert
are not available at runtime.) Instead, the checks throw their own exception.Comments
I think it would make sense to enable this by default on local dev builds. I placed it next to another dev-tool (
tools/extensions/phpstorm
).