Problem/Motivation

In #3101247: Deprecate AssertHelperTrait::castSafeStrings() in favour of MarkupInterfaceComparator we deprecated AssertHelperTrait::castSafeStrings(), but forgot to deprecate the trait itself since there are no other methods in the trait.

Also, the deprecation test annotation for the deprecation of AssertHelperTrait::castSafeStrings was mistyped.

Proposed resolution

Fix the annotation and deprecate the trait itself.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

CommentFileSizeAuthor
#34 interdiff_31_34.txt999 bytesanmolgoyal74
#34 3169171-34.patch4.11 KBanmolgoyal74
#31 3169171-31.patch3.39 KBPooja Ganjage
#29 3169171-29.patch3.39 KBsulfikar_s
#27 3169171-27.patch2.27 KBsulfikar_s
#27 interdiff_26-27.txt358 bytessulfikar_s
#26 interdiff_3169171_24-26.txt870 bytesankithashetty
#26 3169171-26.patch2.32 KBankithashetty
#24 reroll_diff_3169171_20-24.txt1.38 KBankithashetty
#24 3169171-24.patch2.32 KBankithashetty
#20 3169171-20.patch2.96 KBmondrake
#20 interdiff_7-20.txt1.38 KBmondrake
#16 3169171-16.patch3.07 KBayushmishra206
#16 interdiff_7-16.txt379 bytesayushmishra206
#14 3169171-14.patch2.49 KBayushmishra206
#14 interdiff_7-14.txt631 bytesayushmishra206
#7 rawdiff_6-7.txt910 bytesmondrake
#7 3169171-7.patch3.1 KBmondrake
#6 3169171-6.patch2.73 KBmondrake
#5 3169171-5.patch1.53 KBmondrake
#5 3169171-5-test-only.patch1.78 KBmondrake
#4 interdiff_2_4.txt1.75 KBanmolgoyal74
#4 3169171-4.patch1.08 KBanmolgoyal74
#2 3169171-2.patch1.86 KBlongwave
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

mondrake created an issue. See original summary.

longwave’s picture

Status: Active » Needs review
FileSize
1.86 KB

Deprecated the trait, but this breaks the test; the autoloader triggers the deprecation and I can't figure out how to add an expectation for it.

Also spotted a typo in the existing AssertHelperTraitTest, probably should spin that out to a new issue.

Status: Needs review » Needs work

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

anmolgoyal74’s picture

Status: Needs work » Needs review
FileSize
1.08 KB
1.75 KB

I am not sure if this works.

mondrake’s picture

@anmolgoyal74 thanks but no, it doesn't... With deprecations we should not refactor the deprecated code, just add the deprecation elements, https://www.drupal.org/core/deprecation

@longwave re #2 I am afraid we cannot add a @trigger_error at the trait level here, nor we would be able to do so with any test class or test trait. The problem lies in the test discovery process, as the PhpUnitCliTest failure shows in the test-only patch here - AssertHelperTraitTest.php is found during the directory scan, its class Reflected to find the test methods, during reflection the trait is loaded and the @trigger_error fires - hence the deprecation exception captured. Unless we get to find a way to have a mechanism that silences all deprecations catered during the test discovery phase, we are not able to workaround that.

Maybe for a test trait it's sufficient to add @deprecated and skip the @trigger_error?

mondrake’s picture

Uh, maybe this works - moving the AssertHelperTestClass out of the discoverable tests namespaces. It's a bit byzantine though. Thanks @anmolgoyal74 for the inspiration from patch in #4.

mondrake’s picture

With a test method testing the trait's deprecation. We cannot add the @expectedDeprecation to the already exixsting method - since it's a multiple test supported by a data provider, only the first instance would intercept the deprecation since the error is triggered only once at class loading.

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

mondrake’s picture

Title: Deprecate AssertHelperTrait » Fix AssertHelperTrait deprecation
Issue summary: View changes
Issue tags: +Deprecated assertions

Adjusted issue title and summary to cover scope per #2, let's not split further.

longwave’s picture

Status: Needs review » Reviewed & tested by the community

Thanks! This solution works and while it is a bit convoluted, it is only in test code that is to be removed so I don't see any issue with it. It also provides a pattern for us to use again if we need to.

Status: Reviewed & tested by the community » Needs work

The last submitted patch, 7: 3169171-7.patch, failed testing. View results

mondrake’s picture

Status: Needs work » Reviewed & tested by the community

#11 is a random test failure

alexpott’s picture

Status: Reviewed & tested by the community » Needs work
+++ b/core/tests/Drupal/TestTools/AssertHelperTestClass.php
@@ -0,0 +1,21 @@
+<?php
+
+namespace Drupal\TestTools;
+
+use Drupal\Tests\AssertHelperTrait;
+
+/**
+ * A helper class for deprecation of AssertHelperTrait.
+ *
+ * @todo remove this class in Drupal 10.
+ *
+ * @internal
+ */
+class AssertHelperTestClass {
+  use AssertHelperTrait;
+
+  public function testMethod($value) {
+    return $this->castSafeStrings($value);
+  }
+
+}

+++ b/core/tests/Drupal/Tests/AssertHelperTrait.php
--- a/core/tests/Drupal/Tests/AssertHelperTraitTest.php
+++ b/core/tests/Drupal/Tests/AssertHelperTraitTest.php

+++ b/core/tests/Drupal/Tests/AssertHelperTraitTest.php
@@ -3,6 +3,7 @@
+use Drupal\TestTools\AssertHelperTestClass;

Let's not put this in TestTools - it's not necessary as far as I know. And this is not a test tool. I think this can go in core/tests/Drupal/Tests/fixtures.

ayushmishra206’s picture

Status: Needs work » Needs review
FileSize
631 bytes
2.49 KB

Made the changes asked in #13. Please review.

mondrake’s picture

Status: Needs review » Needs work

@ayushmishra206 that seems a bit too far :) The class is necessary, just it's not necessary to reside in the Drupal\TestTools namespace.

ayushmishra206’s picture

Status: Needs work » Needs review
FileSize
379 bytes
3.07 KB

I am sorry, please ignore the previous patch.

alexpott’s picture

Status: Needs review » Needs work
--- /dev/null
+++ b/core/tests/Drupal/TestTools/AssertHelperTestClass.php

@@ -0,0 +1,19 @@
+use Drupal\Tests\AssertHelperTrait;

@@ -3,6 +3,7 @@
+use Drupal\TestTools\AssertHelperTestClass;

We need to move the class to core/tests/Drupal/Tests/fixtures (note the directory needs to be created) and the namespace needs to be changed to namespace Drupal\Tests\fixtures; and therefore the use needs to be changed.

You can run core/tests/Drupal/Tests/AssertHelperTraitTest.php test before uploading to check you have everything correct.

mondrake’s picture

#17 hmm wouldn't the Drupal\Tests\fixtures namespace be in the domain of those discoverable for testing? If so, we'd end up with the same problem.

mondrake’s picture

Assigned: Unassigned » mondrake

On this.

mondrake’s picture

Assigned: mondrake » Unassigned
Status: Needs work » Needs review
FileSize
1.38 KB
2.96 KB

Moving the class file to the core/tests/fixtures directory instead (which is out of the test discovery path), and loading the class with a require_once in the first test.

mondrake’s picture

Looking at this again, I am actually afraid now that this change

+++ b/core/tests/Drupal/KernelTests/KernelTestBase.php
@@ -16,7 +16,6 @@
 use Drupal\Core\Language\Language;
 use Drupal\Core\Site\Settings;
 use Drupal\Core\Test\TestDatabase;
-use Drupal\Tests\AssertHelperTrait;
 use Drupal\Tests\ConfigTestTrait;
 use Drupal\Tests\RandomGeneratorTrait;
 use Drupal\Tests\TestRequirementsTrait;
@@ -76,7 +75,6 @@

@@ -76,7 +75,6 @@
 
   use AssertLegacyTrait;
   use AssertContentTrait;
-  use AssertHelperTrait;
   use RandomGeneratorTrait;
   use ConfigTestTrait;
   use TestRequirementsTrait;

in the parent issue is breaking BC :(

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

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

daffie’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
ankithashetty’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
2.32 KB
1.38 KB

Rerolled the patch in #20. Thanks!

daffie’s picture

Status: Needs review » Needs work
Issue tags: +Needs reroll
+++ b/core/tests/Drupal/Tests/AssertHelperTraitTest.php
@@ -12,10 +12,18 @@
-   * @expectDeprecation AssertHelperTrait::castSafeStrings() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. There is no replacement; assertEquals() will automatically cast MarkupInterface to strings when needed. See https://www.drupal.org/node/3123638
+   * @expectedDeprecation AssertHelperTrait::castSafeStrings() is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. There is no replacement; assertEquals() will automatically cast MarkupInterface to strings when needed. See https://www.drupal.org/node/3123638

@ankithashetty: You missed this change is your reroll.

ankithashetty’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
2.32 KB
870 bytes

Hi @daffie, the code that you mentioned in #25 has been updated in this issue #3172438: Since symfony/phpunit-bridge 5.1: Using "@expectedDeprecation" annotations in tests is deprecated, use the "ExpectDeprecationTrait::expectDeprecation()" method instead.. So, I think it's no longer required. Updated the patch accordingly. Thank you...

sulfikar_s’s picture

Hi,

I've applied the patch in #26 and it applied cleanly. But the file(core/tests/fixtures/AssertHelperTestClass.php) which is created as being part of this is having a 'use' statement that is not being used. which caused the Custom Commands Failure.

I removed that line. Please review.

daffie’s picture

The deprecation in the patch needs to be updated to 9.2.

sulfikar_s’s picture

Status: Needs work » Needs review
FileSize
3.39 KB

Hi, Corrected that to 9.2.

Please review.

daffie’s picture

Status: Needs review » Needs work
+++ b/core/tests/Drupal/Tests/AssertHelperTrait.php
@@ -4,8 +4,15 @@
+@trigger_error(__NAMESPACE__ . '\AssertHelperTrait is deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. There is no replacement. See https://www.drupal.org/node/3123638', E_USER_DEPRECATED);

You missed one.

Pooja Ganjage’s picture

Hi,

Creating a patch as suggested in #30 comment.

Please review the patch.

Thanks.

Pooja Ganjage’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 31: 3169171-31.patch, failed testing. View results

anmolgoyal74’s picture

Status: Needs work » Needs review
FileSize
4.11 KB
999 bytes

Fixed the failing test.

daffie’s picture

Status: Needs review » Reviewed & tested by the community

The trait Drupal\Tests\AssertHelperTrait has only one method and we are deprecating that method.
Therefore we can deprecate the whole trait and that is what is patch does.
There is a deprecation message test added to the patch.
There is also a CR.
For me it is RTBC.

  • catch committed 3302b4e on 9.2.x
    Issue #3169171 by mondrake, anmolgoyal74, ayushmishra206, ankithashetty...
catch’s picture

Status: Reviewed & tested by the community » Fixed

Committed 3302b4e and pushed to 9.2.x. Thanks!

Status: Fixed » Closed (fixed)

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