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

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

alexpott created an issue. See original summary.

alexpott’s picture

Status: Active » Needs review
FileSize
718 bytes

Here's a patch.

mondrake’s picture

Status: Needs review » Reviewed & tested by the community

Yep 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

mondrake’s picture

Issue tags: +PHP 7.2
mondrake’s picture

Assigned: Unassigned » mondrake
Status: Reviewed & tested by the community » Needs work

Probably worth trying to cope with namespaces in all Listeners classes, patch coming soon.

mondrake’s picture

Title: Use the forward compatibility layer for BaseTestListener » Use the forward compatibility layer for listener classes
Assigned: mondrake » Unassigned
Status: Needs work » Needs review
FileSize
4.1 KB
4.27 KB

Here listener classes all implement FC layers where possible.

Status: Needs review » Needs work

The last submitted patch, 6: 2928249-6.patch, failed testing. View results
- codesniffer_fixes.patch Interdiff of automated coding standards fixes only.

mondrake’s picture

So... 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

$ ../vendor/bin/phpunit tests/Drupal/KernelTests/Core/Batch/BatchKernelTest.php --verbose

PHPUnit 6.5.2 by Sebastian Bergmann and contributors.

Runtime:       PHP 7.2.0
Configuration: /home/travis/drupal8/core/phpunit.xml.dist

Testing Drupal\KernelTests\Core\Batch\BatchKernelTest
.                                                                   1 / 1 (100%)

Time: 376 ms, Memory: 6.00MB

OK (1 test, 6 assertions)

See https://travis-ci.org/mondrake/imagemagick/jobs/311349139

Bingo!

But now, #6 breaks with PHPUnit 4.8.36 :( ... kinda catch22 situation here...

alexpott’s picture

Status: Needs work » Closed (duplicate)
Related issues: +#2795317: Allow PHPUnit 6+ support for object mocking

@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.

mondrake’s picture

Aha - cool thanks @alexpott

alexpott’s picture

Status: Closed (duplicate) » Needs work

Actually 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.

alexpott’s picture

Status: Needs work » Needs review
FileSize
11.96 KB

@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.

alexpott’s picture

+++ b/core/phpunit.xml.dist
@@ -49,16 +49,11 @@
   <listeners>
-    <listener class="\Drupal\Tests\Listeners\DeprecationListener">
+    <listener class="\Drupal\Tests\Listeners\DrupalListener">
     </listener>
-    <!-- The Symfony deprecation listener has to come after the Drupal
-    deprecation listener -->
+    <!-- The Symfony deprecation listener has to come after the Drupal listener -->
     <listener class="Symfony\Bridge\PhpUnit\SymfonyTestsListener">
     </listener>
-    <listener class="\Drupal\Tests\Listeners\DrupalStandardsListener">
-    </listener>
-    <listener class="\Drupal\Tests\Listeners\DrupalComponentTestListener">
-    </listener>
   </listeners>

Note in order to test this change if you have a core/phpunit.xml you are going to have to make these sort of changes.

mondrake’s picture

So 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 5.5 => PHPUnit 4.8.36 => test pass
  • PHP 5.6 => PHPUnit 5.7.25 => 1 test failure
  • PHP 7.0 / 7.1 / 7.2 => PHPUnit 6.5.2 => now all fail with 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)
mondrake’s picture

Priority: Normal » Critical

BTW - I think this is Critical too in the sense that it targets getting a passing test suite on PHP 7.2.

mondrake’s picture

Tried 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!

alexpott’s picture

Here'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.

mondrake’s picture

Title: Use the forward compatibility layer for listener classes » Introduce a PHPUnit 6+ compatibility layer for Drupal\Tests\Listeners classes
mondrake’s picture

mondrake’s picture

Status: Needs review » Needs work

I could only find this...

+++ b/core/tests/Drupal/Tests/Listeners/DrupalListener.php
@@ -0,0 +1,36 @@
+  /**
+   * Removes deprecations that we are yet to fix.
+   *
+   * @internal
+   */

Shouldn't this be "Listens to PHPUnit test runs." in this context?

alexpott’s picture

@mondrake yep - thanks for the review.

mondrake’s picture

Status: Needs review » Reviewed & tested by the community

#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.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 21: 2928249-2-21.patch, failed testing. View results

mondrake’s picture

Status: Needs work » Reviewed & tested by the community
larowlan’s picture

This looks good to me, just a couple of minor docs nits

  1. +++ b/core/tests/Drupal/Tests/Listeners/DrupalComponentTestListenerTrait.php
    @@ -5,20 +5,28 @@
    +   * @param $test
    

    nit: missing the parameter type here?

  2. +++ b/core/tests/Drupal/Tests/Listeners/DrupalStandardsListenerTrait.php
    @@ -151,22 +154,58 @@ public function checkValidCoversForTest(TestCase $test) {
    +   * @param $test
    ...
    +   * @param $test
    ...
    +   * @param $test
    

    same?

alexpott’s picture

We can say that these will implement \PHPUnit\Framework\Test|\PHPUnit_Framework_Test so I've added that. Almost tempted to put mixed 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 on PHPUnit_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.

alexpott’s picture

Oops 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 :(

  • larowlan committed 89e64c1 on 8.5.x
    Issue #2928249 by alexpott, mondrake: Introduce a PHPUnit 6+...
larowlan’s picture

Version: 8.5.x-dev » 8.4.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)
Issue tags: +Needs reroll

Committed as 89e64c1 and pushed to 8.5.x

Doesn't apply on 8.4.x

Published change record

larowlan’s picture

Change record versions will need to be updated after backport

mondrake’s picture

alexpott’s picture

Some 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

neclimdul’s picture

I 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?

mondrake’s picture

alexpott’s picture

@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.

jibran’s picture

Or they can wait for 2 more months or use current dev snapshot of 8.5.x.

+1 to not backport it.

mondrake’s picture

It looks like this broke testing on Windows. Filed #2932715: PHPUnit testing fails on Windows since #2928249.

hswong3i’s picture

I give a try with cherry-pick as below, plus some fixes:

git fetch --all
git checkout 8.4.x
git pull
git checkout -b 2928249
git cherry-pick 89e64c1

Most likely changes for core/modules/simpletest/src/WebTestBase.php could be skipped.

Let's see if it could pass the test...

alexpott’s picture

Status: Needs review » Fixed

@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

hswong3i’s picture

@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

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

savkaviktor16@gmail.com’s picture

Issue tags: -Needs reroll