Problem/Motivation
The assert_options() is deprecated in upcoming PHP 8.3 so linter can't pass https://www.drupal.org/pift-ci-job/2719854
- https://wiki.php.net/rfc/assert-string-eval-cleanup and https://www.php.net/manual/en/function.assert-options
Steps to reproduce
/var/www/html/web $ php -r 'assert_options(1);'
PHP Deprecated: Function assert_options() is deprecated in Command line code on line 1
Deprecated: Function assert_options() is deprecated in Command line code on line 1
Proposed resolution
- provide replacement depending on PHP version
- update documentation https://www.drupal.org/node/2492225
- update CR https://www.drupal.org/node/3105918 as assertions no longer a runtime setting
- add change record
Remaining tasks
- agree
- patch/review
- commit
User interface changes
no
API changes
- Assertions are no longer configurable via settings.php
- content entity preSave() now throw LogicException if no validation executed before saving entity
- \Drupal\jsonapi\EventSubscriber\ResourceResponseValidator::doValidateResponse() removed as it exists only to simplify testing
Data model changes
no
Release notes snippet
no
| Comment | File | Size | Author |
|---|
Issue fork drupal-3375693
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
- 3375693-
compare
- 11.x
changes, plain diff MR !4934
- 3375693-assert_options_8.3
changes, plain diff MR !4933
Comments
Comment #2
andypostAttempt to pass sniffers
Comment #3
andypostcombined
Comment #4
andypostLocally I'm getting following
Comment #5
andypostone more attempt, no way to set it runtime
Comment #6
andypostthis test needs rework
Comment #7
andypostcombo with #3374223: Fix deprecated overloaded function usage in PHP 8.3
Comment #8
andypostThe CR https://www.drupal.org/node/3105918 needs update and new CR
The class is deprecated and no-op with 8.3
Comment #9
andypostComment #10
andypost+++ b/core/modules/jsonapi/tests/src/Unit/EventSubscriber/ResourceResponseValidatorTest.phpAccording to the file doc-block this file is not API yet #3032787: [META] Start creating the public PHP API of the JSON:API module
@longwave at slack suggested
Comment #11
andypostAttempt to fix test
The remaining
\Drupal\Tests\system\Functional\Entity\EntityFormTest::testValidationHandlers()failure somehow also related to assertion settings for validation but can;t find the reasonComment #12
andypostfix cs
Comment #13
andypostRe-roll after #3374223: Fix deprecated overloaded function usage in PHP 8.3
Still can't get why assertion
\Drupal\Core\Entity\ContentEntityBase::preSave()is not working inDrupal\Tests\system\Functional\Entity\EntityFormTest::testValidationHandlers()Locally the test passed when
zend.assertions=1which is enabled in CI https://dispatcher.drupalci.org/job/drupal_patches/193991/artifact/jenki... (grep forzend.assertions)Comment #14
andypostThis assertion was added in #3081646: Follow up for "Adding Assertions to Drupal - Test Tools" instead of exception, so probably easier to revert the hunk
Comment #15
andypostFix with TODO to decide
Comment #16
andypostNew failures missed in #3374223: Fix deprecated overloaded function usage in PHP 8.3
https://dispatcher.drupalci.org/job/drupal_patches/195171/testReport/Sit...
Comment #17
andypostTests are green, looking for reviews
Comment #18
andypostRandom failure on pgsql could gone after #2962157: TestSiteApplicationTest requires a database despite being a unit test
Comment #19
andypostthis change means core no longer can manage assertions
Comment #20
andypost@larowlan pointed that CR probably is enough
Comment #21
andypostThe CR should say
- runtime code should have
zend.assertions=0or (-1) asassert.active- tests which has requirement to catch assertions should add doc-block
@requires setting zend.assertions 1https://wiki.php.net/rfc/assert-string-eval-cleanup#formal_proposal
Existing docs https://www.drupal.org/docs/drupal-apis/runtime-assertions#s-configuring... needs to update about
assert.activePhpunit
- https://github.com/sebastianbergmann/phpunit/commit/16282d0b6f664df88a75...
- https://docs.phpunit.de/en/9.6/incomplete-and-skipped-tests.html?highlig... (missing this)
Comment #22
andypostThere's similar issue found #3380147: Use zend.assertions PHP setting instead of assert.active
Comment #23
tunicThe issue posted in #22 is focused the idea is to replace assert.active by zend.assertions in the places where it is used (.htaccess and maybe in user.ini if this file gets added to the codebase). I've marked that issue as duplicated, but now I'm not sure because this issue is dealing with something related but not the same,. Should I reopen the other or deal with the .htaccess here as well?
Comment #24
longwaveJust a heads up that #3371301: Retrieve field type category information in \Drupal\Core\Field\FieldTypePluginManager::getGroupedDefinitions added another assertion test so that one needs to be updated now as well.
Comment #25
andypostThank you! On my side just going to unblock CI image build as we decided to move to latest debian stable but it needs new build infra(
#3365510: Create a DrupalCI Environment for PHP 8.3
Comment #26
andypostWorkaround for #24
Now running PHP 8.3 beta3 in CI
Comment #27
andypostnew failure
Comment #28
andypostPHP 8.2 image using libxml
libXML Compiled Version => 2.9.10but 8.3 using2.9.14- 8.2 https://dispatcher.drupalci.org/job/drupal_patches/199724/artifact/jenki...
- 8.3 https://dispatcher.drupalci.org/job/drupal_patches/199725/artifact/jenki...
Locally on Ubuntu 23.04 using PHP 8.1 with libxml
2.9.14the test case also fails, also tested on Alpinelinux2.11.5where it also fails independently from PHP versionComment #29
andypostFiled new issue for that #3383577: TextSummaryTest:testLength() fails on some libxml versions
Comment #30
andypostPHP RC3 CI run https://www.drupal.org/pift-ci-job/2776702
Comment #31
andypostused to split it out to #3391281: Fix deprecated ReflectionProperty::setValue() usage for PHP 8.3
Comment #33
andypostFiled CR https://www.drupal.org/node/3391611 and opened MR to get faster CI
MR also adds daily run of CI using PHP 8.3 - probably it needs to be extracted to separate issue
patch from 26 still applicable until merged #3391281: Fix deprecated ReflectionProperty::setValue() usage for PHP 8.3 (RTBC ATM)
so that's only blocker for compatibility left
Comment #35
andypostComment #36
andypostRe-roll after #3391281: Fix deprecated ReflectionProperty::setValue() usage for PHP 8.3
Comment #37
andypostUpdated IS with API changes
This change IMO fits in scope as subscribers's methods are not a part of API and the method becomes unused
as the test for the method is removed but maybe better to keep this public method without test?
Comment #38
catchLeft some questions on the MR.
Comment #39
andypostUpdated IS with link to docs to update and rerolled
Primary questions according review
- revert assertion added in 10.1 to
ContentEntityBase(went in without CR so could be reverted as well) #3081646-37: Follow up for "Adding Assertions to Drupal - Test Tools"- should we keep
assert_options()in codebase (settings.local.phpand Kernel) - I think it needs to removal or rewrite https://git.drupalcode.org/project/drupal/-/merge_requests/4933#note_222712- addition of daily run could be moved to separate issue
FYI GA of PHP 8.3.0 Nov 23 2023
Comment #40
andypostAdded commit with removal of
assert_options()- official docs updated already https://www.php.net/manual/function.assert-optionsprobably at https://www.drupal.org/node/2492225 nothing to change as both
assert.activeandassert.exceptionare default to 1 (that's why RFC accepted)EDIT updated CR
Comment #41
quietone commented@andypost, thanks for keeping Drupal up to date with PHP!
I review this issue and as often happens catch and/or longwave have addressed things that I notice as well.
I left a suggestion for text change in the MR.
Other than that the change records needs updated as listed.
Comment #42
andypostI left this place the same as it was before 10.1 (where it was commited without change record).
So I reverted this part of commit as explained https://git.drupalcode.org/project/drupal/-/merge_requests/4933#note_223111
Comment #43
andypostThe change itself https://git.drupalcode.org/project/drupal/-/commit/e434d61d4cc1fec047a89...
it went in without CR so we can be sure it unused
Comment #44
catchI went ahead and added https://www.drupal.org/node/3397979 on the basis that just in case someone runs into this on production, they'd have a chance of finding out why. But the assertion should prevent it from happening in the vast majority of cases so hopefully no-one will have to.
I had one question about a follow-up and applied @quietone's wording suggestion, this looks good to me and happy to commit it if someone else will RTBC it.
Comment #45
longwaveAll feedback has been addressed, this all looks OK to me now.
Comment #48
catchCommitted/pushed to 11.x and cherry-picked to 10.2.x, thanks!
Comment #49
catchLeaving the documentation updates tag. Also adding to Drupal 10.2.0 release highlights and added a note to the release notes.
Comment #50
andypostUpdated CR https://www.drupal.org/node/3105918 to point new one
On docs page it's not clear how to remove mention from htaccess
Filed follow-up to decide about clean-up of it and update docs there
Comment #52
catchDidn't mean to move this back to needs review, back to fixed again!
Comment #55
chi commentedThe change record recommends setting
ini_set('zend.assertions', 1);but that not gonna always work.There is a note about that on php.net.
Not sure what we can do here. Probably just recommend configuring it in php.ini file.
Comment #56
andypostYes, as link to official docs said, to use assertions you need to enable development mode via
pho.iniand then you can disable(0) it viaini_set('zend.assertions', 0);and enable when needed in tests