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
I am trying to build Drupal 8 RPMs for Fedora/EPEL and I am required to unbundle libraries. One such bundled library is PHPUnit. Drupal 8 requires PHPUnit 4.1 while latest Fedora/EPEL provides 4.2 and there are a few incompatibility issues with deprecated functions -- see https://github.com/sebastianbergmann/phpunit/issues/1292 as to why they are deprecated.
-
PHPUnit_Framework_Assert::assertSelectEquals is deprecated
-
core/tests/Drupal/Tests/Core/Template/AttributeTest.php
- Drupal\Tests\Core\Template\AttributeTest::testPrint
-
core/tests/Drupal/Tests/Core/Template/AttributeTest.php
-
PHPUnit_Framework_Assert::assertTag is deprecated
-
core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php
- Drupal\Tests\Core\Utility\LinkGeneratorTest::testGenerateHrefs with data set #0 ('test_route_1', array(), false, '/test-route-1')
- Drupal\Tests\Core\Utility\LinkGeneratorTest::testGenerateHrefs with data set #1 ('test_route_2', array('example'), false, '/test-route-2/example')
- Drupal\Tests\Core\Utility\LinkGeneratorTest::testGenerateHrefs with data set #2 ('test_route_3', array(), true, 'http://example.com/test-route-3')
- Drupal\Tests\Core\Utility\LinkGeneratorTest::testGenerateFromUrl
- Drupal\Tests\Core\Utility\LinkGeneratorTest::testGenerateFromUrlExternal
- Drupal\Tests\Core\Utility\LinkGeneratorTest::testGenerateAttributes
- Drupal\Tests\Core\Utility\LinkGeneratorTest::testGenerateQuery
- Drupal\Tests\Core\Utility\LinkGeneratorTest::testGenerateParametersAsQuery
- Drupal\Tests\Core\Utility\LinkGeneratorTest::testGenerateOptions
- Drupal\Tests\Core\Utility\LinkGeneratorTest::testGenerateXss
- Drupal\Tests\Core\Utility\LinkGeneratorTest::testGenerateWithHtml
- Drupal\Tests\Core\Utility\LinkGeneratorTest::testGenerateActive
-
core/tests/Drupal/Tests/Core/Utility/LinkGeneratorTest.php
https://github.com/phpunit/phpunit-dom-assertions
Proposed resolution
Add https://github.com/phpunit/phpunit-dom-assertions to the required libraries in composer.jsonTry to use DOMTestCase as testclasses for those tests.- Provide alternative methods that cover our use cases for the deprecated method calls
Remaining tasks
- Review patch
- Once this is in we can update PHPUnit. Unpostpone #2387027: Upgrade PHPUnit to the latest stable release
User interface changes
API changes
Original report by @siwinski
Comment | File | Size | Author |
---|---|---|---|
#57 | interdiff.txt | 9.53 KB | pfrenssen |
#57 | 2331685-57.patch | 11.38 KB | pfrenssen |
Comments
Comment #1
siwinski CreditAttribution: siwinski commentedComment #2
dawehnerI guess you could replace it with using symfony css selector + xpath without such a big effort.
Comment #3
siwinski CreditAttribution: siwinski commentedIt looks like that's what https://github.com/phpunit/phpunit-dom-assertions (mentioned in the phpunit issue linked above) is intended to do. It also looks like
assertSelectEquals
is implemented butassertTag
is not yet.Comment #4
jhedstromComment #5
daffie CreditAttribution: daffie commentedComment #6
daffie CreditAttribution: daffie commentedIs it an idea to copy the functions assertTag() and assertSelectEquals() to the class UnitTestCase. Or replace the functions with an other assert call?
The development of phpunit-dom-assertions has stalled.
Comment #7
daffie CreditAttribution: daffie commentedChange the issue to a bug report. Because it is stalling #2387027: Upgrade PHPUnit to the latest stable release.
Comment #8
catchComment #9
catchActually I'm going to go ahead and bump this to critical.
Leaving #2387027: Upgrade PHPUnit to the latest stable release as major since I'm not clear whether the update counts as a minor or major upgrade. Not being able to upgrade PHPUnit at all due to a BC break feels critical though.
If there's a backwards compatible way to fix this, or if we agree that the API change here would be OK in a minor release, we can bump this back down to major. Really don't want to end up with a forked/outdated PHPUnit for the entire lifecycle of 8.x though.
Comment #10
dawehnerWe could leverage https://github.com/phpunit/phpunit-dom-assertions
Given that we have our own base class I went with adding a PR for adding a nice test trait: https://github.com/phpunit/phpunit-dom-assertions/pull/4
but this PR is not a strict requirement to use that library.
Comment #11
dawehnerAdded a proposed solution to the IS.
Comment #12
jibranHere we go.
Comment #15
dawehnerIdeally not all our unit tests would extend from dom test, but well, maybe we have to wait until the trait is in.
Does someone wants to create an issue which moves all our helper methods of the base test into some helper trait?
Comment #16
jibrantest runs fine locally with the patch
Comment #17
dawehner@jibran
Ensure to proxy the phpunit tests via simpletest. It looks like the autoloading doesn't work somehow.
Comment #18
larowlancomposer dump-autoload was the sauce
Comment #19
kim.pepperCan we ask them to tag a stable release?
Comment #20
jibranThere is no stable release yet.
Comment #21
jibranPlease see https://github.com/phpunit/phpunit-dom-assertions/issues/3
Comment #22
larowlanSo should we pin a particular commit in the meantime?
Comment #23
jibranWell last commit was on Aug 27, 2014. So I think it doesn't make much difference.
Comment #24
larowlanAlso #2304461: KernelTestBaseTNG™ and #2232861: Create BrowserTestBase for web-testing on top of Mink are related here.
Comment #25
dawehnerComment #26
jibranHere we go #2403087: Use phpunit-dom-assertions trait to allow simple extensibility of existing test classes
PS: Self quoting is not good. :P
Comment #27
daffie CreditAttribution: daffie commentedCan we not rewrite the tests to use xpath processor. In #1333730: [Meta] PHP DOM (libxml2) misinterprets HTML5 we are adding one for HTML5. If I am wrong about this please tell me.
Comment #28
dawehner@daffie
We talk about a phpunit test here, all that xpath functionality is just included in the simpletest side of things, afaik.
Comment #29
dawehnerI would still argue that we should point to a specific commit, it is the good practise, people read the composer.json file of core.
Comment #30
jibranHere we go.
Comment #31
dawehnerThank you!
Comment #32
alexpottI think the latest stable dom crawler is 2.6.3 but this patch is coming with 2.6.1
Comment #33
jibranAdded "symfony/dom-crawler": "2.6.*", to drupal composer.
Comment #34
larowlanCan we use the more flexible ~2.6 or failing that ^2.6.3 if ~2.6 doesn't force 2.6.3?
Comment #35
jibranThis is what we are doing with all the symfony components so it only seems fair to add 2.6.*
Comment #36
larowlanOk, thanks for that
Comment #37
daffie CreditAttribution: daffie commentedThe only thing in this patch being added is the symfony/dom-crawler library. I cannot see why that is enough to fix the problem as stated in the issue summary.
In #1333730: [Meta] PHP DOM (libxml2) misinterprets HTML5 is spoken about the symfony/dom-crawler library and the consensus is that an other library is far better then this one.
The problem with the symfony/dom-crawler library is that it only supports html4 and Drupal 8 wants html5 support.
So if there is a need for a dom-crawler library I am postponing this issue on #1333730: [Meta] PHP DOM (libxml2) misinterprets HTML5.
Comment #38
jibran@daffie we are not adding
symfony/dom-crawler
we are addingphpunit/phpunit-dom-assertions
. This is a critical issue if you have any other suggestion to fix this please explain.Comment #39
larowlanThis would need a re-roll now that #1975220: Allow a Composer user to manage Drupal, modules, and PHP dependencies with a custom root composer.json is in?
Comment #40
cilefen CreditAttribution: cilefen commentedreroll
Comment #41
jibranThanks for the reroll @cilefen. RTBC anyone?
Comment #42
kim.pepperLets do it.
Comment #43
daffie CreditAttribution: daffie commentedYes, you do!!! I can also see that is a requirement for the phpunit/phpunit-dom-assertions library.
Comment #44
dawehnerSo? The tests for HTML are fine with just HTML 4 support, if we need HTML 5 support we can still switch over later.
This issue allows us to update phpunit in the meantime.
Comment #45
jhedstromThis issue won't be properly resolved until
phpunit/phpunit-dom-assertions
supportsassertTag()
and the other methods marked as deprecated, since without that, our tests that use those assertions fail when running phpunit 4.2+ (the failure is because of the deprecated flag).Comment #46
pfrenssenassertTag()
is only used in\Drupal\Tests\Core\Utility\LinkGeneratorTest
. Isn't it a good plan to replace them with another approach so this can move forward?Comment #47
pfrenssenassertSelectEquals()
is also only used in one test:\Drupal\Tests\Core\Template\AttributeTest
. If we can replace these instances we can update to the new PHPUnit and do not need to add a dependency onphpunit/phpunit-dom-assertions
.Comment #48
pfrenssenPatch overrides the
assertTag()
method that is used inLinkGeneratorTest
with an alternative implementation that uses PHP built-in DOMDocument and DOMXPath classes to assert the tags.If we combine this with the patch from #40 then we already do not need to wait for
phpunit/phpunit-dom-assertions
to add support forassertTag()
before moving on with this issue. I would also propose to investigate whether we can replaceassertSelectEquals()
with an alternative solution.Setting to needs review for the bot. This still needs work.
Comment #49
pfrenssenComment #50
pfrenssenThis patch replaces all occurrences of
assertTag()
andassertSelectEquals()
with self rolled implementations. This should make it unnecessary to includephpunit/phpunit-dom-assertions
.Please review carefully. I am very drunk.
Comment #51
Nick_vhWould be useful if there is some documentation why preserveWhiteSpace needs to be set to FALSE.
if it is deprecated, should we still use inheritdoc? If the method will disappear, so will the documentation.
Comment #52
pfrenssenOk let's try it out for real. Attached patches update PHPUnit to 4.2.6. The first is only the update, without patch. This one should fail with deprecated messages. The second one includes the patch from #50 and should hopefully be green.
If this goes through we can make a followup issue to update PHPUnit itself.
Comment #53
pfrenssen@Nick_vh, thanks for the review! I'll address your remarks and will post an updated patch. In the meanwhile I'll set the status back to needs review temporarily so we can get feedback from the bot.
Comment #56
pfrenssenOk so we need to replace
assertNotTag()
as well.Comment #57
pfrenssenAddressed the remarks from #51.
preserveWhiteSpace()
is not actually needed, so I removed it.assertLink()
since we are only testing links here, not tags in general. This also allowed to simplify the calling code a bit.I also implemented an alternative for the 2 calls to
assertNotTag()
.2 patches attached: first is the vanilla patch, the second one includes the update of PHPUnit to 4.2.6 to prove that it actually works with the new version.
Comment #58
pfrenssenAnother experiment, PHPUnit 4.2.x is also quite old already. Let's see how our test suite fares using the patch and the very latest PHPUnit 4.4.2.
The actual patch to review is the first patch from #57.
Comment #59
jibranAwesome work @pfrenssen. Why not move these new function to
UnitTestBase
?Comment #60
pfrenssenWow all tests green on PHPUnit 4.4.2! That is great news, I always had understood that it would be very hard to update PHPUnit due to their lack of backwards compatibility.
I have created a followup issue to do this: #2409667: Update to PHPUnit 4.4.2.
Comment #61
pfrenssen@jibran, I think these tests methods are too narrow in scope to be of general use. It's true we have a need for parsing HTML, but #1333730: [Meta] PHP DOM (libxml2) misinterprets HTML5 seems like the ideal solution for this. I'd rather get that in than maintaining our own set of DOMDocument based parsing in UnitTestBase.
Comment #62
jibranOk then. From #50 onward issue completely changed directions so I think I can RTBC this. Thanks @pfrenssen for the explanation.
Comment #63
jibran@pfrenssen you created #2409667: Update to PHPUnit 4.4.2 but we do have #2387027: Upgrade PHPUnit to the latest stable release
Comment #64
pfrenssenOhh I had been searching the issue queue extensively before creating the issue, but I was using the keyword "update" instead of "upgrade".
Thanks for the RTBC!
Comment #65
pfrenssenComment #66
alexpottThis issue addresses a critical bug and is allowed per https://www.drupal.org/core/beta-changes. Committed 3e43de7 and pushed to 8.0.x. Thanks!