Commit 3302b4e0 authored by catch's avatar catch
Browse files

Issue #3169171 by mondrake, anmolgoyal74, ayushmishra206, ankithashetty,...

Issue #3169171 by mondrake, anmolgoyal74, ayushmishra206, ankithashetty, sulfikar_s, longwave, Pooja Ganjage, daffie, alexpott: Fix AssertHelperTrait deprecation
parent 81e2d9c0
Loading
Loading
Loading
Loading
+9 −2
Changes for core/tests/Drupal/Tests/AssertHelperTrait.php: 9 added lines, 2 removed lines.
Original line number Diff line number Diff line
@@ -4,8 +4,15 @@

use Drupal\Component\Render\MarkupInterface;

@trigger_error(__NAMESPACE__ . '\AssertHelperTrait is deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. There is no replacement. See https://www.drupal.org/node/3123638', E_USER_DEPRECATED);

/**
 * Provides helper methods for assertions.
 *
 * @deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. There is no
 *   replacement.
 *
 * @see https://www.drupal.org/node/3123638
 */
trait AssertHelperTrait {

@@ -18,13 +25,13 @@ trait AssertHelperTrait {
   * @return mixed
   *   The input value, with MarkupInterface objects casted to string.
   *
   * @deprecated in drupal:9.1.0 and is removed from drupal:10.0.0. There is no
   * @deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. There is no
   *   replacement, just use assertEquals in tests.
   *
   * @see https://www.drupal.org/node/3123638
   */
  protected static function castSafeStrings($value) {
    @trigger_error('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', E_USER_DEPRECATED);
    @trigger_error('AssertHelperTrait::castSafeStrings() is deprecated in drupal:9.2.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', E_USER_DEPRECATED);
    if ($value instanceof MarkupInterface) {
      $value = (string) $value;
    }
+7 −10
Changes for core/tests/Drupal/Tests/AssertHelperTraitTest.php: 7 added lines, 10 removed lines.
Original line number Diff line number Diff line
@@ -12,12 +12,18 @@
 */
class AssertHelperTraitTest extends UnitTestCase {

  public function testTraitDeprecation(): void {
    $this->expectDeprecation('Drupal\Tests\AssertHelperTrait is deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. There is no replacement. See https://www.drupal.org/node/3123638');
    require_once __DIR__ . '/../../fixtures/AssertHelperTestClass.php';
    $class = new AssertHelperTestClass();
  }

  /**
   * @covers ::castSafeStrings
   * @dataProvider providerCastSafeStrings
   */
  public function testCastSafeStrings($expected, $value) {
    $this->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');
    $this->expectDeprecation('AssertHelperTrait::castSafeStrings() is deprecated in drupal:9.2.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');
    $class = new AssertHelperTestClass();
    $this->assertSame($expected, $class->testMethod($value));
  }
@@ -34,12 +40,3 @@ public function providerCastSafeStrings() {
  }

}

class AssertHelperTestClass {
  use AssertHelperTrait;

  public function testMethod($value) {
    return $this->castSafeStrings($value);
  }

}
+19 −0
Changes for core/tests/fixtures/AssertHelperTestClass.php: 19 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php

namespace Drupal\Tests;

/**
 * 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);
  }

}