Runtime Assertions where introduced in Drupal 8.0 at the last moment without a long term plan for their phase in. I propose the following two rules moving forward:
Rule #1: If it ain't broke, don't break it.
The way Drupal 8 is currently set up adding a new assertion can cause contrib modules to fail in the dev environment until they are fixed if they made an incorrect call to the API, say by using an integer when the PHPDocs say to use a string. To avoid this I propose that moving forward the only new assertions added in the 8.x branch are those that stop the code from proceeding to a cryptic error state, such as in issue #2558079: Assertions in \Drupal\Template\TwigExtension. In that example if the code is in a state where the assertion would fail the system will crash anyway, so there will be no extant modules with the bad services configuration in question that would suddenly start failing. If they exist at all they'll already be failing, the assertion just means they fail in a more understandable way.
Rule #2: Unit Test assertions watching for bad YAML files
Under normal circumstances writing a unit test against an assertion is like writing a unit test for a unit test - redundant. For the assertions that are guarding against bad configurations though my opinion has changed to where I think it is worth the time to write a unit showing that the assertion will fire. Part of this is due to the nature of .yml files - they are sometimes edited by admin users and also get crafted as part of quick one-of modules that will likely never see rigorous unit testing.
If this sounds good to everyone I'll rewrite the pending TwigExtension assertion following this principle.
Comments
Comment #2
cilefen commentedComment #14
quietone commentedThere has not been any discussion on this proposal in the 8 years it has been open.
It is a policy statement needed for the use of assertions?
I am setting the status to Postponed (maintainer needs more info). If we don't receive information to help with the issue, it may be closed after three months.
Thanks!
Comment #15
smustgrave commentedBeen about 6 months now, twice the 3 month mark. Going to close out. If still desired feel free to re-open
Thanks!