Problem/Motivation

symfony/phpunit-bridge 5.2.0 will bring the capability to add baseline files for deprecations, https://github.com/symfony/symfony/pull/37733

We should implement that to make simpler to avoid introducing new usages of deprecated things while legacy codebase is being cleaned up.

Proposed resolution

MR 1660 --- USING the baseline

This is rather trivial. You have a baseline file --> just indicate it in the PHPUnitBridge configuration and you're done.

MR 2372 --- GENERATING the baseline

sligthly more complicated:

  • run-tests.sh executes parallel test runs, each of which generating a baseline file of its own
  • at the end of each test suite run on DrupalCI, the individual files are consolidated first in a suite baseline file, and then each suite file into a full baseline file
  • at the end of the DrupalCI test run, you find the generated full baseline file in the test run artifacts at artifacts/run_tests.javascript/phpunit-xml/full_deprecation_baseline.json
  • then you can update the baseline file for usage in core/.deprecation-baseline.json (see MR 1660 above)

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Issue fork drupal-3180042

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

mondrake created an issue. See original summary.

mondrake’s picture

Status: Postponed » Active

symfony/phpunit-bridge 5.2.0 was released today

Pooja Ganjage’s picture

StatusFileSize
new428 bytes

Hi,

Creating a patch for this issue.

Please review the patch.

Thanks.

Pooja Ganjage’s picture

Status: Active » Needs review

Status: Needs review » Needs work

The last submitted patch, 3: 3180042-3.patch, failed testing. View results

anmolgoyal74’s picture

Status: Needs work » Needs review
StatusFileSize
new959 bytes
new1.18 KB

Status: Needs review » Needs work

The last submitted patch, 6: 3180042-6.patch, failed testing. View results

anmolgoyal74’s picture

Status: Needs work » Needs review
StatusFileSize
new1.46 KB
new406 bytes
mondrake’s picture

Status: Needs review » Needs work

Removing all the entries

diff --git a/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php
index 2ef406c29d..7fcbff7132 100644
--- a/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php
+++ b/core/tests/Drupal/Tests/Listeners/DeprecationListenerTrait.php
@@ -100,46 +100,6 @@ public static function getSkippedDeprecations() {
     return [
       // The following deprecation message is skipped for testing purposes.
       '\Drupal\Tests\SkippedDeprecationTest deprecation',
-      // The following Symfony deprecations are introduced in the Symfony 4
-      // development cycle. They will need to be resolved prior to Symfony 5
-      // compatibility.
-      'The "Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesser" class is deprecated since Symfony 4.3, use "Symfony\Component\Mime\MimeTypes" instead.',
-      'The "Drupal\Core\File\MimeType\MimeTypeGuesser" class implements "Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface" that is deprecated since Symfony 4.3, use {@link MimeTypesInterface} instead.',
-      'The "Symfony\Component\HttpFoundation\File\MimeType\FileBinaryMimeTypeGuesser" class is deprecated since Symfony 4.3, use "Symfony\Component\Mime\FileBinaryMimeTypeGuesser" instead.',
-      'The "Symfony\Component\HttpFoundation\File\MimeType\FileinfoMimeTypeGuesser" class is deprecated since Symfony 4.3, use "Symfony\Component\Mime\FileinfoMimeTypeGuesser" instead.',
-      'The "Drupal\Tests\Core\DependencyInjection\Compiler\LegacyMimeTypeGuesser" class implements "Symfony\Component\HttpFoundation\File\MimeType\MimeTypeGuesserInterface" that is deprecated since Symfony 4.3, use {@link MimeTypesInterface} instead.',
-      'The "Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher::dispatch()" method will require a new "string|null $eventName" argument in the next major version of its interface "Symfony\Contracts\EventDispatcher\EventDispatcherInterface", not defining it is deprecated.',
-      'The "Drupal\Component\EventDispatcher\ContainerAwareEventDispatcher::dispatch()" method will require a new "string|null $eventName" argument in the next major version of its parent class "Symfony\Contracts\EventDispatcher\EventDispatcherInterface", not defining it is deprecated.',
-      // The following deprecation is listed for Twig 2 compatibility when unit
-      // testing using \Symfony\Component\ErrorHandler\DebugClassLoader.
-      'The "Twig\Environment::getTemplateClass()" method is considered internal. It may change without further notice. You should not extend it from "Drupal\Core\Template\TwigEnvironment".',
-      '"Symfony\Component\DomCrawler\Crawler::text()" will normalize whitespaces by default in Symfony 5.0, set the second "$normalizeWhitespace" argument to false to retrieve the non-normalized version of the text.',
-      // PHPUnit 8.
-      "The \"PHPUnit\TextUI\ResultPrinter\" class is considered internal This class is not covered by the backward compatibility promise for PHPUnit. It may change without further notice. You should not use it from \"Drupal\Tests\Listeners\HtmlOutputPrinter\".",
-      "The \"Drupal\Tests\Listeners\DrupalListener\" class implements \"PHPUnit\Framework\TestListener\" that is deprecated Use the `TestHook` interfaces instead.",
-      "The \"Drupal\Tests\Listeners\DrupalListener\" class uses \"PHPUnit\Framework\TestListenerDefaultImplementation\" that is deprecated The `TestListener` interface is deprecated.",
-      "The \"PHPUnit\Framework\TestSuite\" class is considered internal This class is not covered by the backward compatibility promise for PHPUnit. It may change without further notice. You should not use it from \"Drupal\Tests\TestSuites\TestSuiteBase\".",
-      // Simpletest's legacy assertion methods.
-      'UiHelperTrait::drupalPostForm() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. Use $this->submitForm() instead. See https://www.drupal.org/node/3168858',
-      'AssertLegacyTrait::assertEqual() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertEquals() instead. See https://www.drupal.org/node/3129738',
-      'AssertLegacyTrait::assertNotEqual() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertNotEquals() instead. See https://www.drupal.org/node/3129738',
-      'AssertLegacyTrait::assertIdentical() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertSame() instead. See https://www.drupal.org/node/3129738',
-      'AssertLegacyTrait::assertNotIdentical() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertNotSame() instead. See https://www.drupal.org/node/3129738',
-      'AssertLegacyTrait::assertText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseContains() or $this->assertSession()->pageTextContains() instead. See https://www.drupal.org/node/3129738',
-      'AssertLegacyTrait::assertNoText() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseNotContains() or $this->assertSession()->pageTextNotContains() instead. See https://www.drupal.org/node/3129738',
-      'AssertLegacyTrait::assertRaw() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseContains() instead. See https://www.drupal.org/node/3129738',
-      'AssertLegacyTrait::assertNoRaw() is deprecated in drupal:8.2.0 and is removed from drupal:10.0.0. Use $this->assertSession()->responseNotContains() instead. See https://www.drupal.org/node/3129738',
-      // PHPUnit 9.
-      "The \"PHPUnit\TextUI\DefaultResultPrinter\" class is considered internal This class is not covered by the backward compatibility promise for PHPUnit. It may change without further notice. You should not use it from \"Drupal\Tests\Listeners\HtmlOutputPrinter\".",
-      'assertFileNotExists() is deprecated and will be removed in PHPUnit 10. Refactor your code to use assertFileDoesNotExist() instead.',
-      'assertRegExp() is deprecated and will be removed in PHPUnit 10. Refactor your code to use assertMatchesRegularExpression() instead.',
-      'assertNotRegExp() is deprecated and will be removed in PHPUnit 10. Refactor your code to use assertDoesNotMatchRegularExpression() instead.',
-      'assertDirectoryNotExists() is deprecated and will be removed in PHPUnit 10. Refactor your code to use assertDirectoryDoesNotExist() instead.',
-      'Support for using expectException() with PHPUnit\\Framework\\Error\\Warning is deprecated and will be removed in PHPUnit 10. Use expectWarning() instead.',
-      'Support for using expectException() with PHPUnit\\Framework\\Error\\Error is deprecated and will be removed in PHPUnit 10. Use expectError() instead.',
-      'assertDirectoryNotIsWritable() is deprecated and will be removed in PHPUnit 10. Refactor your code to use assertDirectoryIsNotWritable() instead.',
-      'assertFileNotIsWritable() is deprecated and will be removed in PHPUnit 10. Refactor your code to use assertFileIsNotWritable() instead.',
-      'The at() matcher has been deprecated. It will be removed in PHPUnit 10. Please refactor your test to not rely on the order in which methods are invoked.',
     ];
   }
 

and running the command

SIMPLETEST_DB={your_db_url} SYMFONY_DEPRECATIONS_HELPER='generateBaseline=TRUE&baselineFile=test.deprecation.json' vendor/phpunit/phpunit/phpunit -c core core/modules/action/tests/src/Kernel/Migrate/d6/MigrateActionsTest.php

you get a test.deprecation.json that contains

[
    {
        "location": "Drupal\\Tests\\Listeners\\DrupalListener::endTest",
        "message": "The \"PHPUnit\\TextUI\\DefaultResultPrinter\" class is considered internal This class is not covered by the backward compatibility promise for PHPUnit. It may change without further notice. You should not use it from \"Drupal\\Tests\\Listeners\\HtmlOutputPrinter\".",
        "count": 1
    },
    {
        "location": "Drupal\\Tests\\Listeners\\DrupalListener::endTest",
        "message": "The \"Drupal\\Tests\\Listeners\\DrupalListener\" class implements \"PHPUnit\\Framework\\TestListener\" that is deprecated Use the `TestHook` interfaces instead.",
        "count": 1
    },
    {
        "location": "Drupal\\Tests\\Listeners\\DrupalListener::endTest",
        "message": "The \"Drupal\\Tests\\Listeners\\DrupalListener\" class uses \"PHPUnit\\Framework\\TestListenerDefaultImplementation\" that is deprecated The `TestListener` interface is deprecated.",
        "count": 1
    },
    {
        "location": "Drupal\\Tests\\action\\Kernel\\Migrate\\d6\\MigrateActionsTest::testActions",
        "message": "The \"Symfony\\Component\\HttpFoundation\\File\\MimeType\\MimeTypeGuesser\" class is deprecated since Symfony 4.3, use \"Symfony\\Component\\Mime\\MimeTypes\" instead.",
        "count": 1
    },
    {
        "location": "Drupal\\Tests\\action\\Kernel\\Migrate\\d6\\MigrateActionsTest::testActions",
        "message": "The \"Symfony\\Component\\HttpFoundation\\File\\MimeType\\FileBinaryMimeTypeGuesser\" class is deprecated since Symfony 4.3, use \"Symfony\\Component\\Mime\\FileBinaryMimeTypeGuesser\" instead.",
        "count": 1
    },
    {
        "location": "Drupal\\Tests\\action\\Kernel\\Migrate\\d6\\MigrateActionsTest::testActions",
        "message": "The \"Symfony\\Component\\HttpFoundation\\File\\MimeType\\FileinfoMimeTypeGuesser\" class is deprecated since Symfony 4.3, use \"Symfony\\Component\\Mime\\FileinfoMimeTypeGuesser\" instead.",
        "count": 1
    },
    {
        "location": "Drupal\\Tests\\action\\Kernel\\Migrate\\d6\\MigrateActionsTest::testActions",
        "message": "AssertLegacyTrait::assertIdentical() is deprecated in drupal:8.0.0 and is removed from drupal:10.0.0. Use $this->assertSame() instead. See https://www.drupal.org/node/3129738",
        "count": 40
    }
]

that is, all the deprecation triggered that were previously silenced now get summarised in the file.

Brainstorming: what we need to do here (and it's quite a lot) is to be able to produce a file for each test run (because we cannot have a single file, run-tests.sh does parallelise the test execution in multiple processes), and consolidate the files into one with the summary at the end of the complete run. That file will be the 'entire' baseline for Drupal. Then, that baseline should be generated with a special test run on DrupalCI that would update the deprecation baseline every (?), and be included in the repo (?)

During the normal test runs, the 'baseline file' should be unpacked and re-allocated for each test run so that the single test baseline could be checked against its run results.

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new16.01 KB

Let's get DrupalCI to generate merge this baseline files for us. And then we should have something we can commit to core as a baseline.

alexpott’s picture

StatusFileSize
new1.13 KB
new15.92 KB

Trying a new location on DrupalCI after chatting to @mixologic

alexpott’s picture

StatusFileSize
new873 bytes
new15.92 KB

Php notices... let's ignore them for now...

alexpott’s picture

alexpott’s picture

StatusFileSize
new1.11 KB
new15.93 KB

Let's try this again...

alexpott’s picture

StatusFileSize
new1.28 KB
new16.03 KB

And again...

alexpott’s picture

StatusFileSize
new2.67 KB
new18.04 KB

Once more into the breach...

Status: Needs review » Needs work

The last submitted patch, 17: 3180042-17.patch, failed testing. View results

alexpott’s picture

Status: Needs work » Needs review
StatusFileSize
new1021 bytes
new18.05 KB

Ah we always have a temporary file...

alexpott’s picture

StatusFileSize
new835 bytes
new18.05 KB

Let there be one file.

alexpott’s picture

StatusFileSize
new1.06 KB
new18.07 KB

Let's use the correct file mode!

alexpott’s picture

StatusFileSize
new1.97 KB
new16.1 KB

Now let's reset drupalci.yml and get files for all the different runs.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mondrake’s picture

Version: 9.4.x-dev » 10.0.x-dev
Assigned: Unassigned » mondrake
Status: Needs review » Needs work

Moving to MR workflow and bumped to D10

mondrake’s picture

The baseline has 1000s of entries related to the usage of legacy Symfony 3 MimeType classes, which I suppose would go away once #3197482: Update Drupal 10 to depend on Symfony 5.4 (as a stepping stone to Symfony 6, for deprecation checking support) is in.

However, this makes me think whether we should have somewhere a list of deprecation patterns to be ignored while building the baseline as well as while comparing against it, a la PHPStan. That’s probably something for upstream, though.

Also, now the baseline is split per test suite following the logic DrupalCI (unit, kernel, build, etc), so in any case we will need to manually merge it on a first run, unless an infra job will be able to do it.

alexpott’s picture

mondrake’s picture

Issue summary: View changes

MR 1655 is about GENERATING the baseline

mondrake’s picture

Issue summary: View changes

MR 1660 is about USING the baseline

mondrake’s picture

Assigned: mondrake » Unassigned
mondrake’s picture

StatusFileSize
new612.16 KB

Attached, the baseline that is resulting by 'merging' manually the files under

artifacts/run_tests.{test-suite}/phpunit-xml/deprecation_baseline.json

for each of the DrupalCI testsuite runs (build, functional, javascript, kernel, phpunit).

There are lots of deprecations thrown in the listeners like

    {
        "location": "Drupal\\Tests\\Listeners\\DrupalListener::endTest",
        "message": "The \"PHPUnit\\TextUI\\DefaultResultPrinter\" class is considered internal This class is not covered by the backward compatibility promise for PHPUnit. It may change without further notice. You should not use it from \"Drupal\\Tests\\Listeners\\HtmlOutputPrinter\".",
        "count": 1
    },

that would trigger for each single test... another reason for an 'ignoreFile' per #27.

mondrake’s picture

mondrake’s picture

If we had #35 from upstream, then I think we would no longer need to bypass PHPUnitBridge's deprecation management, so we would not longer need a deprecation listener (or whatever it will be in PHPUnit 10). At the same time we could allow contrib to alter the ignore file, so not needing #3143388: Allow projects to add to the list of skipped deprecations either

mondrake’s picture

Issue tags: +PHPUnit 10

Rerolled

mondrake’s picture

mondrake’s picture

Issue summary: View changes
mondrake’s picture

MR 2372 is built on top of #3272779: [Symfony 6.1] Replace deprecationListenerTrait with PHPUnitBridge ignoreFile, and modifies run-tests.sh script only, so that baseline consolidation from different files occurs at the end of each run-tests.sh execution. It does not interact with Symfony's internals.

mondrake’s picture

Issue summary: View changes
mondrake’s picture

Assigned: Unassigned » mondrake
Issue summary: View changes
Status: Postponed » Active

Working on this.

mondrake’s picture

Status: Active » Needs review

After #3272779: [Symfony 6.1] Replace deprecationListenerTrait with PHPUnitBridge ignoreFile, this is now rather simple.

MR 1660 --- USING the baseline

This is rather trivial. You have a baseline file --> just indicate it in the PHPUnitBridge configuration and you're done.

MR 2372 --- GENERATING the baseline

Just sligthly more complicated:

  • run-tests.sh executes parallel test runs, each of which generating a baseline file of its own
  • at the end of each test suite run on DrupalCI, the individual files are consolidated first in a suite baseline file, and then each suite file into a full baseline file
  • at the end of the DrupalCI test run, you find the generated full baseline file in the test run artifacts at artifacts/run_tests.javascript/phpunit-xml/full_deprecation_baseline.json
  • then you can update the baseline file for usage in core/.deprecation-baseline.json (see MR 1660 above)
mondrake’s picture

The automated baseline generation includes also deprecations triggered from within tests marked @legacy, which does not make much sense.

Opened issue upstream, https://github.com/symfony/symfony/issues/46710

mondrake’s picture

Title: Add baseline for deprecation testing » [PP-upstream] Add baseline for deprecation testing
Status: Needs review » Postponed

PR merged upstream, let's wait for a Symfony patch release update.

mondrake’s picture

For an approach when to use ignoreFile and when a baselineFile, https://drupal.slack.com/archives/C1BMUQ9U6/p1655711760320739

Let’s include that in a CR

mondrake’s picture

Assigned: mondrake » Unassigned
mondrake’s picture

Title: [PP-upstream] Add baseline for deprecation testing » [PP-1] Add baseline for deprecation testing

Upstram fixed. Now postponed on #3292730: Update to Symfony 6.1.2.

spokje’s picture

Title: [PP-1] Add baseline for deprecation testing » Add baseline for deprecation testing
Status: Postponed » Needs review

Blocker #3292730: Update to Symfony 6.1.2 just landed, unpostponing.

mondrake’s picture

Issue summary: View changes
mondrake’s picture

StatusFileSize
new119.4 KB

Squashing together MR 2372 and #2664570: Move Attribute classes under Drupal\Component to see what baseline juice we get

Status: Needs review » Needs work

The last submitted patch, 53: 3180042-53-test-only.patch, failed testing. View results

mondrake’s picture

OK, now test the baseline generated by #53 (available at https://dispatcher.drupalci.org/job/drupal_patches/136993/artifact/jenki...) with MR 1660.

mondrake’s picture

StatusFileSize
new1.19 MB
mondrake’s picture

StatusFileSize
new1.25 MB

Well, we need to include #2664570: Move Attribute classes under Drupal\Component too to make it meaningful.

mondrake’s picture

StatusFileSize
new1.25 MB

Suppress commit checks for the purpose of testing

mondrake’s picture

StatusFileSize
new1.3 MB
mondrake’s picture

Status: Needs work » Needs review

So, what the experiments in #56 and #59 tell us:

a) the concept of deprecation baseline is different from the PHPStan baseline. It's more a 'watermark': while in PHPStan if you correct an issue without cleaning up the baseline you will get an error reporting that PHPStan was expecting an error that did not show up, this is not happening for this baseline. You can have less deprecations occurring in a test, and no error shown. But you can't have more than those in the baseline.

b) for the case of #2664570: Move Attribute classes under Drupal\Component, the generated baseline is huge, and on a run with the baseline applied we have more errors showing up --> probably it will be fair to add a ignore pattern in the ignoreFile in this case instead of baselining.

Back to NR since MR 1660 is practically the scope that needs to be done here based on the issue title - the baseline generation should probably be a separate issue.

longwave’s picture

Status: Needs review » Reviewed & tested by the community

The changes are as minimal as can be to get the first version of this in so we can start using it.

andypost’s picture

Status: Reviewed & tested by the community » Needs work

It does not pass tests

andypost’s picture

Status: Needs work » Reviewed & tested by the community

sorry, confused by files, there's MR !1660

catch’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs change record

We need a change record here, and maybe core documentation updates:
- how do you generate the baseline
- how do you use the baseline (presumably nothing special?)
- how do you remove items from the baseline
- when should you continue to use the ignore list instead.

I think it'd be also useful even if we want to generate the baseline in a different issue to be able to see what that looks like for the current state of core, and what if anything would stay in the ignore list.

wim leers’s picture

Status: Needs review » Needs work

While working on #3316274-71: Stabilize FunctionalJavascript testing AJAX: add ::assertExpectedAjaxRequest(), I struggled a lot to add a new expected/ignored deprecation 😅 That's how I stumbled upon this issue.

It sounds like this is still worth doing? 🤓

mondrake’s picture

wim leers’s picture

#66: Yes, and those links are exactly what I looked at to figure out how to do #65. What I meant to say in #65 was that having examples of how to generate baselines would also implicitly provide examples for how to explicitly ignore specific deprecations 🤓

mondrake’s picture

Related, #3295618: Get PHPStan baseline generation via DrupalCI. IIUC the idea is that we should not use DrupalCI to generate baselines, either there or here - rather wait for availability of an infra that could allow that more easily.

Version: 10.0.x-dev » 11.x-dev

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

mondrake’s picture

Status: Needs work » Closed (won't fix)

PHPUnit bridge will not have a PHPUnit 10 compatible version. Deprecation baseline is now available from PHPUnit itself, but that would be a different story.