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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

neclimdul created an issue. See original summary.

neclimdul’s picture

Implements skipping logic in quick/dirty method.

neclimdul’s picture

Status: Active » Needs review
neclimdul’s picture

Status: Needs review » Needs work
Issue tags: +DX (Developer Experience)

Shoot, I used the PHP 7 only options. Not sure how to implement something similar in a PHP 5 compatible way...

Aki Tendo’s picture

Without 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.

$this->assertTrue(ASSERT_ACTIVE);

PHPunit will then give that as the failure reason instead of something unrelated.

neclimdul’s picture

FileSize
6.38 KB
5.47 KB

Whoa, 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.

Version: 8.2.x-dev » 8.3.x-dev

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

jhedstrom’s picture

Status: Needs work » Closed (duplicate)
Related issues: +#2934701: Improve assertion test failures with bad zend.assertions value

Closing as a duplicate of #2934701: Improve assertion test failures with bad zend.assertions value since that has more recent momentum.