Issue #3169171 by mondrake, anmolgoyal74, ayushmishra206, ankithashetty, sulfikar_s, longwave, Pooja Ganjage, daffie, alexpott: Fix AssertHelperTrait deprecation

merge-requests/259/head
catch 2021-01-18 16:13:14 +00:00
parent 81e2d9c051
commit 3302b4e0fb
3 changed files with 35 additions and 12 deletions

View File

@ -4,8 +4,15 @@ namespace Drupal\Tests;
use Drupal\Component\Render\MarkupInterface; 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. * 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 { trait AssertHelperTrait {
@ -18,13 +25,13 @@ trait AssertHelperTrait {
* @return mixed * @return mixed
* The input value, with MarkupInterface objects casted to string. * 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. * replacement, just use assertEquals in tests.
* *
* @see https://www.drupal.org/node/3123638 * @see https://www.drupal.org/node/3123638
*/ */
protected static function castSafeStrings($value) { 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) { if ($value instanceof MarkupInterface) {
$value = (string) $value; $value = (string) $value;
} }

View File

@ -12,12 +12,18 @@ use Drupal\Core\Render\Markup;
*/ */
class AssertHelperTraitTest extends UnitTestCase { 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 * @covers ::castSafeStrings
* @dataProvider providerCastSafeStrings * @dataProvider providerCastSafeStrings
*/ */
public function testCastSafeStrings($expected, $value) { 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(); $class = new AssertHelperTestClass();
$this->assertSame($expected, $class->testMethod($value)); $this->assertSame($expected, $class->testMethod($value));
} }
@ -34,12 +40,3 @@ class AssertHelperTraitTest extends UnitTestCase {
} }
} }
class AssertHelperTestClass {
use AssertHelperTrait;
public function testMethod($value) {
return $this->castSafeStrings($value);
}
}

View File

@ -0,0 +1,19 @@
<?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);
}
}