Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
When running tests without assertions enabled developers get an unhelpful failure with the error message hidden.
Proposed resolution
Skip the tests and provide a useful notice as to why the test can't run.
Remaining tasks
Discuss, Review, Document Best Practice?, Commit
User interface changes
N/A
API changes
N/A
Data model changes
N/A
Comment | File | Size | Author |
---|---|---|---|
#6 | improve_failures_for-2714595-6.patch | 5.47 KB | neclimdul |
#6 | interdiff.2714595.txt | 6.38 KB | neclimdul |
Comments
Comment #2
neclimdulImplements skipping logic in quick/dirty method.
Comment #3
neclimdulComment #4
neclimdulShoot, I used the PHP 7 only options. Not sure how to implement something similar in a PHP 5 compatible way...
Comment #5
Aki Tendo CreditAttribution: Aki Tendo commentedWithout knowing the specific circumstance it's a little hard to give precise advice. As a rule of thumb, runtime assertions shouldn't be tested for - doing so is the equivalent of writing a unit test to test a unit test - and that can go on indefinitely.
Still on occasion it will be desirable to do such a test - particularly to insure the system doesn't enter a dangerous state causing data loss if an assertion is skipped - although in that particular circumstance an exception might be more appropriate. One example that does exist in the Drupal code is the test of simpletest's handling of runtime assertions.
With all the above in mind, a unit test that needs assertions to be on should assertTrue against the ASSERT_ACTIVE flag.
PHPunit will then give that as the failure reason instead of something unrelated.
Comment #6
neclimdulWhoa, after banging my head on this and talking to Aki in IRC turns out this is sort of hard to test for. 5 behaves weird, 7's backwards compatibility isn't 100% and they behave a bit differently. So I moved the logic to a helper on our base class. I think I've got it all working.
Aki promised me a update to the assertions handbook page documenting how to setup your environment for testing assertions so I'll update the message to deep link to that after its been written but this should be functionally complete.
Comment #14
jhedstromClosing as a duplicate of #2934701: Improve assertion test failures with bad zend.assertions value since that has more recent momentum.