function AssertHelperTrait::castSafeStrings

Same name and namespace in other branches
  1. 9 core/tests/Drupal/Tests/AssertHelperTrait.php \Drupal\Tests\AssertHelperTrait::castSafeStrings()

Casts MarkupInterface objects into strings.

Parameters

string|array $value: The value to act on.

Return value

mixed The input value, with MarkupInterface objects casted to string.

35 calls to AssertHelperTrait::castSafeStrings()
AssertHelperTestClass::testMethod in core/tests/Drupal/Tests/AssertHelperTraitTest.php
BlockInterfaceTest::testBlockInterface in core/modules/block/tests/src/Kernel/BlockInterfaceTest.php
Test configuration and subsequent form() and build() method calls.
BookUninstallValidatorTest::testValidateEntityQueryWithoutResults in core/modules/book/tests/src/Unit/BookUninstallValidatorTest.php
@covers ::validate
BookUninstallValidatorTest::testValidateEntityQueryWithResults in core/modules/book/tests/src/Unit/BookUninstallValidatorTest.php
@covers ::validate
BookUninstallValidatorTest::testValidateNotBook in core/modules/book/tests/src/Unit/BookUninstallValidatorTest.php
@covers ::validate

... See full list

File

core/tests/Drupal/Tests/AssertHelperTrait.php, line 21

Class

AssertHelperTrait
Provides helper methods for assertions.

Namespace

Drupal\Tests

Code

protected static function castSafeStrings($value) {
    if ($value instanceof MarkupInterface) {
        $value = (string) $value;
    }
    if (is_array($value)) {
        array_walk_recursive($value, function (&$item) {
            if ($item instanceof MarkupInterface) {
                $item = (string) $item;
            }
        });
    }
    return $value;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.