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
The current way of deprecation functionality is the following: Add @deprecated as of ...
to our function signatures/classes.
This has a couple of disadvantages:
- Its really just documentation, nothing happens on runtime
- Its not covering all usecases, like a different (maybe additional) parameter to a function/value of a parameter
Proposed resolution
Use @trigger_error($message, E_USER_DEPRECATED);
. With the @ the error is hidden by default.
https://github.com/symfony/phpunit-bridge thought provides an error handler which makes those deprecation errors visible in tests.
With that we gain both the possiblity to slowly deprecate stuff, while migrating them over time, but still a way to ensure that those are actually thrown. The bridge adds some test helpers for it.
Remaining tasks
User interface changes
API changes
Comment | File | Size | Author |
---|---|---|---|
#75 | interdiff-2488860.txt | 1.73 KB | catch |
#75 | 2488860-75.patch | 15.27 KB | catch |
#71 | 2488860-2-71.patch | 13.7 KB | alexpott |
Comments
Comment #1
dawehnerComment #2
dawehnerMeh, merged all the work together but will extract things into their own methods.
Let's first see how the code reacts, sadly my patch is too big atm :(
Comment #3
dawehnerHere is the first extract: #2489122: Get rid of calls to deprecated API calls.
Comment #4
dawehnerFor now just phpunit-bridge + use it
Comment #5
jibranShould we remove this once we'll upgrade to symofony 2.7.0?
Can we move this up with rest of the symfony components?
I think this is not intentional.
Comment #6
dawehnerWell .. kinda yes ...
Comment #7
daffie CreditAttribution: daffie commentedThis patch is adding a new library to drupal core. So there is a Dries approval necessary.
The issue summary need an update to better explain why this library is necessary.
Why do you want the dev-master and not regular version 2.7 or 2.8?
You say that this is intentional. The value is now set to 32767. Can you explain why you want it changed.
Comment #8
daffie CreditAttribution: daffie commentedComment #9
dawehnerThis is no longer true with the new core structure, gladly!!!!!!!!!!
Comment #10
daffie CreditAttribution: daffie commented@dawehner: Do you have a link for me to that info. :-)
Comment #11
dawehner#2457875: [policy] Evolving and documenting Drupal core's structure, responsibilities, and decision-making
Comment #12
daffie CreditAttribution: daffie commented@dawehner: Thanks.
Comment #15
jgeryk CreditAttribution: jgeryk commentedWorking on reroll
Comment #16
jgeryk CreditAttribution: jgeryk commentedComment #17
daffie CreditAttribution: daffie commentedSetting the status to "Needs review". Now the testbot will test the patch.
Comment #21
alexpottComment #23
alexpottHere's a test and added the @group legacy to all the places in core where necessary. This change is going to need a change record and probably a core group announcement :)
Comment #24
alexpottThe reason I went for the dev version is the ErrorAssert class that is coming in Symfony 3.2 - it just makes writing tests so much easier.
Comment #25
dawehnerIts quite nice how the phpunit bridge solves the problem. Is it okay for now to just detect the deprecations in phpunit and not in webtestcase?
Here is a small expansion of the test coverage.
Comment #26
alexpottGood idea - we can wrap all of that up in a data provider to make testing anything additional simple.
Given we're moving away from Simpletest I think at best the integration with that should be a follow-up.
Comment #27
dawehnerI'll work on a change record/better issue summary.
Comment #28
dawehnerComment #29
dawehnerHere is a change record: https://www.drupal.org/node/2811561
Comment #30
alexpottComment #31
alexpott@dawehner nice change record, we probably need a docs page as well. And obviously before all of this we need to firm up the policy on #2575081: [policy, no patch] Use E_USER_DEPRECATED in Drupal 8 minor releases
Comment #32
dawehnerLet's postpone this on the policy issue first.
Comment #34
xjmThe policy issue has been adopted now, so we can continue work here. Yay!
Comment #35
alexpottNew patch reflecting the fact Symfony 3.2 is out and re-rolled on top of 8.4.x.
Comment #36
alexpottThe bridge has changed - they now use annotations... see https://symfony.com/doc/current/components/phpunit_bridge.html
Comment #39
dawehnerInteresting.
Comment #40
dawehnerHere is a quick reroll
Comment #41
dawehnerOnce this task is done we should update the change record to remember people to update the phpunit.xml file based upon the phpunit.xml.dist file. Could we maybe check that somehow as part of UnitTestCase or so that the listener is registered or so?
Comment #43
Mile23Trying to add deprecation errors to deprecated hooks here: #2866779: Add a way to trigger_error() for deprecated hooks
But the path ahead is unclear because core doesn't really even know what to do with
@trigger_error()
at this point, so postponing on this issue.Comment #44
claudiu.cristeaHere's a reroll
Comment #46
Mile23The test results of #44: https://www.drupal.org/pift-ci-job/646796
They tell us there's deprecated code in core (edited):
(There's also a fail of
Drupal\simpletest\Tests\UiPhpUnitOutputTest
, which is probably related to one of these other deprecation failures.)So we need child issues to remove usages of those deprecated items.
Also, at some point, we're going to mark
TestBase
andWebTestBase
as deprecated. At that point, we'll be unable to test those classes using phpunit-based tests unless we just don't add@trigger_error()
to the deprecation.It'll also be interesting to see what explodes when, for instance,
\Drupal::entityManager()
throws this error as it should. That's every entity factory method.Comment #47
Mile23Plan for deprecating hooks: #2870058: [policy, no patch] Document how to deprecate hooks
Linked here because if a defined function is marked as
@deprecated
, then the IDE can show you that it's deprecated. If a hook is deprecated, we only have@trigger_error()
at run time.Comment #48
heddnRe-titling to focus on deprecation. The solution being proposed here doesn't do anything to help with things like the legitimate failure in #2705925-35: ImageItem presave() fails when pointing to a non-existing file entity. Where the node migration is throwing a simple warning and getting converted into an Exception, which is killing the migration.
Comment #49
alexpottLet's mark the tests as legacy and then file followups to remove it in the case of the Twig and Migrate tests - at least we get the benefit of this sooner rather than later.
Comment #50
alexpottThis change is because the bridge adds an additional line of output.
It's the echo here...
Comment #52
alexpottMissed one.
Comment #53
alexpottCreated #2870134: Twig loader "Drupal\Core\Template\Loader\StringLoader" should implement Twig_SourceContextLoaderInterface since version 1.27 to deal with the Twig deprecation.
Comment #54
alexpottCreated #2870138: \Drupal\migrate_drupal\Plugin\migrate\cckfield\CckFieldPluginBase is deprecated - replace usages for the migrate one.
It also occurs to me that we need a followup to implement something for BrowserTestBase to catch deprecated usages in the system under test.
Comment #55
dawehnerNice!
Comment #56
Mile23+1 on @group legacy, with follow-ups.
Here's a test you can add to the patch to prove that @trigger_error() gets swallowed somewhere in a functional test, so we do need a follow-up for BrowserTestBase.
Also, the change record references Symfony\Bridge\PhpUnit\ErrorAssert which I couldn't find documented, and which my IDE couldn't find.
Comment #57
alexpottOpened follow up #2870194: Ensure that process-isolated tests can use Symfony's PHPunit bridge to catch usages of deprecated code and fixed CR. Re-uploading patch in #52 since the last patch on the issue should be the one to commit.
Comment #58
Mile23Kewl. Sorry about the extra patch.
Comment #59
alexpott@Mile23 np - it's useful! I linked it from the new issue.
Comment #60
alexpottThe migrate issue is #2833206: Convert Migrate's cckfield plugins to use the new field plugins - there was one already.
Comment #61
Mile23Go go go. :-)
Note that symfony/phpunit-bridge also gives us some handy mocks: https://symfony.com/doc/current/components/phpunit_bridge.html
Comment #63
alexpottYay for legacy testing and the @group legacy... also adding a deprecation notice to a test class is interesting.
Comment #64
Mile23Deprecation trigger comes from #2824610: Rename DedupeBase/DedupeEntity process plugins to MakeUnique and add documentation
Provisionally RTBCing, because I can run
--testsuite unit
faster than the testbot.Update: Never post something like that when it only says 90% complete.
Comment #65
alexpottThanks @Mile23!
Comment #66
Mile23Updated deprecation policy to tell people not to deprecate tests: https://www.drupal.org/core/deprecation
Comment #67
alexpottOnce this lands we should update the policy with a note about testing.
Comment #69
Mile23Still RTBC since #65 fixes all the things.
Comment #70
jibran#2712647: Update Symfony components to ~3.2 is in so the patch needs a reroll.
This can be updated to 3.2.8 now.
Comment #71
alexpottRerolled because of #2712647: Update Symfony components to ~3.2. Also that added some more deprecated code paths so fixed them or added @group legacy as necessary.
Comment #72
jibranThanks back to RTBC.
Comment #73
jibranComment #75
catchFixing those three YAML files, let's see how this one does.
Comment #76
alexpottI've reviewed the changes @catch has made in #75. The fun fact about the YamlTest is that it existing to detect where the duplicate keys are not the same. One of the supported parsers trusts the first and the other trusts the last. Which is good because removal is therefore for correct.
This is a non root schema duplicate so order is relevant. The only config I found that has this key is core/modules/content_moderation/tests/modules/content_moderation_test_views/config/install/views.view.latest.yml and the order is the as after this patch so @catch has removed the correct one.
Comment #77
catchAdded review credit for @daffie and @jibran.
Committed/pushed to 8.4.x, thanks!
Comment #79
xjmComment #80
Mile23@trigger_error() conflicts with DrupalStandardsListener: #2878248: DrupalStandardsListener improper handling of @trigger_error() deprecation