Problem/Motivation

In order to get to PHPUnit 6 and PHP7.2 compatibility we had to change SYMFONY_DEPRECATIONS_HELPER to weak_vendors because we were triggering deprecation notices from our mocks. PHPUnit 6 has a neat new feature that triggers deprecation messages from mocks if the method has an @deprecated annotation. So even if the method's real code has no @trigger_error its mock will do. This is great because it allows us to find tests which are mocking deprecated methods but it tricky for Drupal 8 because we have methods that were deprecated before we had the @trigger_error policy in place.

This was a hack to get around that. We should be on strict so that all deprecations in core are either skipped or expected. Eventually we should get rid of the skipped deprecations too. See #2959269: [meta] Core should not trigger deprecated code except in tests and during updates.

When it is set to weak_vendors we don't trigger deprecation errors for things like #2961688: Fix "Using UTF-8 route patterns without setting the "utf8" option" deprecation because this deprecation is triggered by vendor code calling vendor code - even though it is our usage of the Symfony API that triggers it.

Proposed resolution

Probably add all the deprecations to skipped so at least we know the size of the work.

It's important to run the tests on both PHP 5.6 and PHP 7+ to get the difference between PHPUnit 4 and PHPUnit 6.

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

Issue summary: View changes
Status: Active » Needs review
FileSize
1.87 KB

Status: Needs review » Needs work

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

alexpott’s picture

Status: Needs work » Needs review
FileSize
14.41 KB

Working on making it not fail.

Status: Needs review » Needs work

The last submitted patch, 4: 2961691-4.patch, failed testing. View results

Berdir’s picture

  1. +++ b/core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php
    @@ -20,6 +20,12 @@ class YamlSymfonyTest extends YamlTestBase {
        * @covers ::decode
        * @dataProvider providerEncodeDecodeTests
    +   *
    +   * @group legacy
    +   * @expectedDeprecation Using the Yaml::PARSE_KEYS_AS_STRINGS flag is deprecated since Symfony 3.4 as it will be removed in 4.0. Quote your keys when they are evaluable instead.
    +   *
    +   * Note the expected deprecation and legacy should be removed when the
    +   * SymfonyYaml::PARSE_KEYS_AS_STRINGS flag is removed from YamlSymfony.
        */
       public function testEncodeDecode($data) {
    

    I guess it's easier to wait for that issue to land and then remove them. The only reason we're not seeing tons of these is because we use the extension on testbot, but anyone running the tests locally or elsewhere would still get them lots of other tests too?

  2. +++ b/core/tests/Drupal/Tests/Core/Entity/EntityLinkTest.php
    @@ -120,6 +127,13 @@ public function testLink($entity_label, $link_text, $expected_text, $link_rel =
    +   *
    +   * @group legacy
    +   *
    +   * Note this is only a legacy test because it triggers a call to
    +   * \Drupal\Core\Entity\EntityTypeInterface::getLabelCallback() which is mocked
    +   * and triggers a deprecation error. Remove when ::getLabelCallback() is
    +   * removed.
        */
    

    just commenting on this as a cross-reference for #2949964: Add an EntityOwnerTrait to standardize the base field needed by EntityOwnerInterface as we have a similar case there.

alexpott’s picture

alexpott’s picture

Hopefully fixed all the things.

The main patch includes the two linked in #7.

The last submitted patch, 8: 2961691-8.no-other-patches.patch, failed testing. View results

alexpott’s picture

The last submitted patch, 8: 2961691-8.patch, failed testing. View results

The last submitted patch, 10: 2961691-9.no-other-patches.patch, failed testing. View results

The last submitted patch, 13: 2961691-13.no-other-patch.patch, failed testing. View results

idebr’s picture

I was about to do a courtesy reroll after #2962736: phpunit.xml.dist has an incorrect instruction on how to disable deprecation errors was committed. However, in #2962736-5: phpunit.xml.dist has an incorrect instruction on how to disable deprecation errors #5 @alexpott mentions:

Eventually we want to swap this back [to a commented line]

+++ b/core/phpunit.xml.dist
@@ -28,8 +28,8 @@
-    <!-- To disable deprecation testing uncomment the next line. -->
-    <env name="SYMFONY_DEPRECATIONS_HELPER" value="weak_vendors"/>
+    <!-- To disable deprecation testing set the value to disabled. -->
+    <env name="SYMFONY_DEPRECATIONS_HELPER" value="strict"/>

In the patch the SYMFONY_DEPRECATIONS_HELPER value is updated to 'strict'.

In line with the comment in#2962736-5, I would like to suggest this environment variable is omitted completely, so its value will default to 'strict'. See ./vendor/symfony/phpunit-bridge/Tests/DeprecationErrorHandler/default.phpt or https://symfony.com/blog/new-in-symfony-2-7-phpunit-bridge :

This behavior can be controlled with the SYMFONY_DEPRECATIONS_HELPER environment variable (default value = strict)

alexpott’s picture

@idebr good point. Rerolled

The patch includes #2912169: Inject the argument resolver into HttpKernel::__construct which will hopefully land soon.

Status: Needs review » Needs work

The last submitted patch, 16: 2961691-2-16.patch, failed testing. View results

alexpott’s picture

Status: Needs work » Needs review
FileSize
676 bytes
77.73 KB
alexpott’s picture

alexpott’s picture

Issue summary: View changes

Updated issue summary to be clear about why we went to weak_vendors and to help explain some of the changes in the patch.

timmillwood’s picture

  1. +++ b/core/modules/forum/tests/src/Unit/Breadcrumb/ForumListingBreadcrumbBuilderTest.php
    @@ -139,11 +140,12 @@ public function testBuild() {
         $forum_manager = $this->getMock('Drupal\forum\ForumManagerInterface');
    

    Maybe this should be moved down to the first place it's used now?

  2. +++ b/core/modules/forum/tests/src/Unit/ForumUninstallValidatorTest.php
    @@ -232,3 +233,17 @@ public function testValidateHasTermsForVocabularyNoAccess() {
    +class TestUrl extends Url {
    

    This seems useful enough to sit outside of FormUninstallValidatorTest.

  3. +++ b/core/modules/forum/tests/src/Unit/ForumUninstallValidatorTest.php
    @@ -232,3 +233,17 @@ public function testValidateHasTermsForVocabularyNoAccess() {
    +  protected $string;
    ...
    +  public function __construct($string) {
    ...
    +  public function toString($collect_bubbleable_metadata = FALSE) {
    

    Should these have docblocks?

alexpott’s picture

Thanks for the review @timmillwood.
1. Sure why not. Not strictly related to the patch but no reason not too.
2&3. Removed in favour of just mocking the URL object.

Berdir’s picture

Status: Needs review » Needs work

Was hoping to RTBC but found a few doc things that should be fixed.

  1. +++ b/core/modules/forum/src/Breadcrumb/ForumBreadcrumbBuilderBase.php
    @@ -59,6 +66,7 @@ public function __construct(EntityManagerInterface $entity_manager, ConfigFactor
         $this->forumManager = $forum_manager;
         $this->setStringTranslation($string_translation);
    +    $this->termStorage = $entity_manager->getStorage('taxonomy_term');
       }
     
    

    I suppose it is very unlikely that anyone subclassed this..

  2. +++ b/core/modules/forum/tests/src/Unit/Breadcrumb/ForumListingBreadcrumbBuilderTest.php
    @@ -177,6 +179,8 @@ public function testBuild() {
         );
     
    +    $forum_manager = $this->getMock('Drupal\forum\ForumManagerInterface');
    +
    

    change this to ::class while we move it around? you do it elsewhere..

  3. +++ b/core/modules/serialization/src/EntityResolver/UuidResolver.php
    @@ -15,16 +15,15 @@ class UuidResolver implements EntityResolverInterface {
        *
        * @var \Drupal\Core\Entity\EntityManagerInterface
        */
    -  protected $entityManager;
    +  protected $entityRepository;
    

    wrong @var

  4. +++ b/core/modules/serialization/src/EntityResolver/UuidResolver.php
    @@ -15,16 +15,15 @@ class UuidResolver implements EntityResolverInterface {
        *
    -   * @param \Drupal\Core\Entity\EntityManagerInterface $entity_manager
    -   *   The entity manager.
    +   * @param \Drupal\Core\Entity\EntityRepositoryInterface $entity_repository
        */
    -  public function __construct(EntityManagerInterface $entity_manager) {
    -    $this->entityManager = $entity_manager;
    +  public function __construct(EntityRepositoryInterface $entity_repository) {
    +    $this->entityRepository = $entity_repository;
       }
    

    missing description

  5. +++ b/core/scripts/run-tests.sh
    @@ -826,11 +826,7 @@ function simpletest_script_run_one_test($test_id, $test_class) {
         }
         else {
    -      // Prevent deprecations caused by vendor code calling deprecated code.
    -      // This also prevents mock objects in PHPUnit 6 triggering silenced
    -      // deprecations from breaking the test suite. We should consider changing
    -      // this to 'strict' once PHPUnit 4 is no longer used.
    -      putenv('SYMFONY_DEPRECATIONS_HELPER=weak_vendors');
    +      putenv('SYMFONY_DEPRECATIONS_HELPER=strict');
         }
    

    was wondering if we should also remove this and rely on the default or whatever it is set, but I guess it's fine?

alexpott’s picture

Status: Needs work » Needs review
FileSize
2.11 KB
30.17 KB

Thanks for the review @Berdir.

  1. Yeah and it is only adding a property and if your sub class has a $termStorage property and it's not the term storage well - /me shrugs. Also this issue is only for 8.6.x.
  2. I'd rather not because I've only done that on new mocks and this is not a new mock - I only moved it because @timmillwood asked.
  3. Fixed
  4. Fixed
  5. Good point we should just use whatever you have in your phpunit.xml (if you've overridden) or the default. I've documented this.
Berdir’s picture

Status: Needs review » Reviewed & tested by the community

1. Fair enough :)

Looks good now I think!

timmillwood’s picture

+1 to RTBC

Re: #24.2 - I only suggested moving it because the usages had been removed, and the only remaining usage was now miles away to it seemed odd. Maybe we should open a follow-up to replace all getMock() usages to use ::class 😉.

catch’s picture

Status: Reviewed & tested by the community » Fixed
+++ b/core/scripts/run-tests.sh
@@ -310,7 +310,12 @@ function simpletest_script_help() {
+              this is not set the value specified in the
+              SYMFONY_DEPRECATIONS_HELPER environment variable, or the value
+              specified in core/phpunit.xml (if it exists), or the default value
+              will used. The default is that any unexpected silenced deprecation
+              error will fail tests.

will be used. Fixed on commit.

Committed c2585a1 and pushed to 8.6.x. Thanks!

  • catch committed c2585a1 on 8.6.x
    Issue #2961691 by alexpott, Berdir, timmillwood, idebr: Change...

Status: Fixed » Closed (fixed)

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