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
We should be using the forward compatibility layer in \Drupal\Tests\Listeners\DeprecationListener as this makes moves to PHPUnit 5 and 6 much simpler.
Proposed resolution
\Drupal\Tests\Listeners\DrupalStandardsListener already uses it. This was just a mistake.
Remaining tasks
User interface changes
None
API changes
None
Data model changes
None
Comment | File | Size | Author |
---|---|---|---|
#38 | drupal-8.4.x-phpunit6_compatibility_layer-2928249-38.patch | 33.45 KB | hswong3i |
#26 | 2928249-2-26.patch | 21.32 KB | alexpott |
#26 | 21-26-interdiff.txt | 3.27 KB | alexpott |
Comments
Comment #2
alexpottHere's a patch.
Comment #3
mondrakeYep this is fine, however not yet enough to let tests pass on PHPUnit 6 :( - will report more in #2927806: Use PHPUnit 6 for testing when PHP version >= 7.2
Comment #4
mondrakeComment #5
mondrakeProbably worth trying to cope with namespaces in all Listeners classes, patch coming soon.
Comment #6
mondrakeHere listener classes all implement FC layers where possible.
Comment #8
mondrakeSo... with the patch in #6 plus others as indicated in #2927806-29: Use PHPUnit 6 for testing when PHP version >= 7.2, I can get a single test to run successfully on PHP 7.2 + PHPUnit 6.5.2
See https://travis-ci.org/mondrake/imagemagick/jobs/311349139
Bingo!
But now, #6 breaks with PHPUnit 4.8.36 :( ... kinda catch22 situation here...
Comment #9
alexpott@mondrake we're going to need to do something like in https://github.com/symfony/phpunit-bridge/blob/master/SymfonyTestsListen... I think we should roll this into #2795317: Allow PHPUnit 6+ support for object mocking and make it a single issue as this will prepare us for 5+ I'm going to work on that now.
Comment #10
mondrakeAha - cool thanks @alexpott
Comment #11
alexpottActually we have \Drupal\Tests\Listeners\DeprecationListener, \Drupal\Tests\Listeners\DrupalComponentTestListener, \Drupal\Tests\Listeners\DrupalStandardsListener and \Drupal\Tests\Listeners\HtmlOutputPrinter that all need addressing so let's try and keep scopes as narrow as possible.
Comment #12
alexpott@mondrake - i think this should allow us to pass with PHPUnit 5 & 6 (with the other appropriate patches applied) and PHPUnit 4.8.36
The patch doesn't address
\Drupal\Tests\Listeners\HtmlOutputPrinter
yet.Comment #13
alexpottNote in order to test this change if you have a core/phpunit.xml you are going to have to make these sort of changes.
Comment #14
mondrakeSo I ended up creating a sandbox on GitHub to do testing separate from the Imagemagick module repo I was using so far... so we do not get across the specifics of that module.
https://github.com/mondrake/d8-php72
This is running on TravisCI this script https://github.com/mondrake/d8-php72/blob/master/.travis.yml so we can test under PHP 5.5, 5.6, 7.0, 7.1 and 7.2 with several patches applied (see in the script), letting composer freely update PHPUnit to the highest version supported on each PHP release, then running tests for
--group Database
.Results here https://travis-ci.org/mondrake/d8-php72/builds/311462660 :
PHP Fatal error: Class 'PHPUnit_Framework_TestSuite' not found in /home/travis/drupal8/core/tests/TestSuites/TestSuiteBase.php on line 10
(at least, no more with the listeners)Comment #15
mondrakeBTW - I think this is Critical too in the sense that it targets getting a passing test suite on PHP 7.2.
Comment #16
mondrakeTried with a single test
phpunit tests/Drupal/KernelTests/Core/Batch/BatchKernelTest.php --verbose
. All GREEN in all releases/all PHPUnit versions :)https://travis-ci.org/mondrake/d8-php72/builds/311475324
Wow!
Comment #17
alexpottHere's an updated version based on work in #2927806: Use PHPUnit 6 for testing when PHP version >= 7.2. The latest patch gets round an issue that when using --group on PHPUnit tests it was loading all the classes in Listeners which breaks when you try to support multiple PHP versions.
Comment #18
mondrakeComment #19
mondrakeAdded a draft CR @ https://www.drupal.org/node/2928884
Comment #20
mondrakeI could only find this...
Shouldn't this be "Listens to PHPUnit test runs." in this context?
Comment #21
alexpott@mondrake yep - thanks for the review.
Comment #22
mondrake#2927806-56: Use PHPUnit 6 for testing when PHP version >= 7.2 and #2923015-50: [PHP 7.2] Incompatible method declarations and #51 show how this patch is necessary to enable testing on PHP 7.2. My contribution in coding is really minor so I'll be bold and RTBC it.
Comment #24
mondrakerandom fail due to https://www.drupal.org/project/drupal/issues/2926309
Comment #25
larowlanThis looks good to me, just a couple of minor docs nits
nit: missing the parameter type here?
same?
Comment #26
alexpottWe can say that these will implement
\PHPUnit\Framework\Test|\PHPUnit_Framework_Test
so I've added that. Almost tempted to putmixed
since this is where the looser typing allows us to be compatible with both PHP 4 and PHP 6. The reason we can;'t just say\PHPUnit\Framework\Test
is because we've got to implement \PHPUnit_Framework_BaseTestListener and that typehints onPHPUnit_Framework_Test
and therefore we need both\Drupal\Tests\Listeners\DrupalListener
and\Drupal\Tests\Listeners\Legacy\DrupalListener
Also noticed another docs bug whilst checking everything.
Comment #27
alexpottOops too many files uploaded... https://www.drupal.org/files/issues/2928249-2-26_0.patch and https://www.drupal.org/files/issues/2928249-2-26_0.patch are the correct ones. I.e. the last two. I noticed the problem with \Drupal\Tests\Listeners\HtmlOutputPrinterTrait's docs whilst uploading :(
Comment #29
larowlanCommitted as 89e64c1 and pushed to 8.5.x
Doesn't apply on 8.4.x
Published change record
Comment #30
larowlanChange record versions will need to be updated after backport
Comment #31
mondrakeI am not sure if this can (or makes sense anyway) be backported to 8.4.x without backporting #2870194: Ensure that process-isolated tests can use Symfony's PHPunit bridge to catch usages of deprecated code too?
Comment #32
alexpottSome of the earlier PHP 7.2 changes were only put into 8.5.x by @catch. Re-rolling this for 8.4.x will be fun because we definitely should not backport #2870194: Ensure that process-isolated tests can use Symfony's PHPunit bridge to catch usages of deprecated code
Comment #33
neclimdulI guess this works but its reliance on traits is weird and this isn't really extensible in a way that would help anyone else that ran into the problem as a sitedev or contrib developer. Why didn't we just provide a base class that picks the right phpunit class and call it a day?
Comment #34
mondrakeGiven #2932574: Indicate Drupal 8.4.x is not compatible with PHP7.2 I think the backport won't happen. Mark fixed?
Comment #35
alexpott@mondrake well we could chose to backport all the other changes to make life simpler for someone who wanted to run 8.4.x on 7.2 by applying patches.
Comment #36
jibranOr they can wait for 2 more months or use current dev snapshot of 8.5.x.
+1 to not backport it.
Comment #37
mondrakeIt looks like this broke testing on Windows. Filed #2932715: PHPUnit testing fails on Windows since #2928249.
Comment #38
hswong3i CreditAttribution: hswong3i commentedI give a try with cherry-pick as below, plus some fixes:
Most likely changes for
core/modules/simpletest/src/WebTestBase.php
could be skipped.Let's see if it could pass the test...
Comment #39
alexpott@hswong3i thanks for he re-roll here. At the moment the decision is to not make 8.4.x PHP 7.2 compatible because it requires API changes that are very close to API breaks - see #2923015: [PHP 7.2] Incompatible method declarations
Comment #40
hswong3i CreditAttribution: hswong3i commented@alexpott thank you for pointing out the latest update ;-)
Thanks god that the official Release Note for Drupal 8.4.4 already updated as NOT recommend PHP 7.2 which I mainly concern with:
https://www.drupal.org/node/2934241/revisions/view/10777131/10778532
Comment #42
savkaviktor16@gmail.com CreditAttribution: savkaviktor16@gmail.com at Skilld commented