Problem/Motivation
We're testing deprecation messages using Symfony's PHPUnit bridge. We're doing so in ways that were not envisaged by the original design and we need the ability to dynamically set expected deprecation messages. I've opened a PR to do this upstream but we can achieve this in Drupal by using a trait.
This came up in #2858482: Simplify REST routing: disallow requesting POST/PATCH in any format, make consistent that is adding tonnes of messages to \Drupal\Tests\Listeners\DeprecationListenerTrait::getSkippedDeprecations() which is not really want we want. We need to be removing messages from there and not adding them.
Here's the related symfony PR: https://github.com/symfony/symfony/pull/25757
Proposed resolution
Add a trait so people can do $this->setExpectedDeprecation()
in tests.
Remaining tasks
User interface changes
None
API changes
Addition to tests and probably only the tests that use the trait. We could use the trait in the base classes but that might not be worth it.
Data model changes
None
Comment | File | Size | Author |
---|---|---|---|
#10 | 2935755-10.patch | 4.81 KB | alexpott |
#10 | 7-10-interdiff.txt | 2.89 KB | alexpott |
#7 | 2935755-7.patch | 4.89 KB | alexpott |
#7 | 4-7-interdiff.txt | 618 bytes | alexpott |
#4 | 2935755-3.patch | 4.65 KB | alexpott |
Comments
Comment #2
alexpottComment #3
alexpottHere's a trait that can give us the functionality without upstream changes (https://github.com/symfony/symfony/pull/25757).
Comment #4
alexpottComment #5
Wim LeersWe can land this now and remove it if https://github.com/symfony/symfony/pull/25757 lands and when we update to a Symfony version that includes it? :)
Comment #6
Wim LeersIf we do commit this, we should:
@internal
@todo
here to remove this once https://github.com/symfony/symfony/pull/25757 lands and we update to a Symfony release that includes itComment #7
alexpottHere's #6 done.
Comment #8
Wim Leers👌
Comment #9
neclimdulI've been thinking about this in a similar issue for assert() expectations, should we use the phpunit 6 style
expectDeprecation()
style or the oldersetExpectedDeprecation()
style or provide both?Comment #10
alexpott@neclimdul I think it makes sense to only support the latest naming. Eventually we'll move off PHPUnit 4 so aiming for PHPUnit 6 will be more consistent. Happy to add a
setExpectedDeprecation()
if people feel having both styles is important.Comment #11
alexpottComment #12
neclimdulnot the prettiest patch with all that reflection but you work with the interface you have. 👍
Comment #13
alexpott@neclimdul or don't have. Symfony have quite reasonably moved my related PR to Symfony 4.1 and new features are not being added to Symfony 3 so we might need to try out this solution for the time being. That said it might be possible to use the 4.1 version of PHPUnit bridge because it has no dependencies per se.
Comment #14
Wim LeersWe'll need to ensure that https://github.com/symfony/symfony/pull/25757 also includes
expectDeprecation()
then, otherwise the@todo
is wrong.I'd update https://github.com/symfony/symfony/pull/25757, but … GitHub is down…
Comment #15
alexpott@Wim Leers I already did that this morning :)
Comment #16
Wim LeersOF COURSE you did!
❤️ Alex Pott 👌
Comment #17
larowlanThe reflection here is a shame, but its the best we can do with what we currently have.
And the phpunit version dance is the same deal, and consistent with other code in core.
There is no impact here, other than tests but it does allow us to keep our exception list lean.
Committed 75f9e43 and pushed to 8.6.x
Cherry-picked as 86b363e and pushed to 8.5.x
#2858482: Simplify REST routing: disallow requesting POST/PATCH in any format, make consistent is in too, so can we get a follow-up to remove that large list and use this new API.
Thanks!
Comment #18
Wim LeersCreated #2936704: Remove REST route deprecations from DeprecationListenerTrait::getSkippedDeprecations(), use ExpectDeprecationTrait::expectDeprecation() instead for #17.