function FormattableMarkupTest::testUnexpectedPlaceholder

Same name in other branches
  1. 8.9.x core/tests/Drupal/Tests/Component/Render/FormattableMarkupTest.php \Drupal\Tests\Component\Render\FormattableMarkupTest::testUnexpectedPlaceholder()
  2. 10 core/tests/Drupal/Tests/Component/Render/FormattableMarkupTest.php \Drupal\Tests\Component\Render\FormattableMarkupTest::testUnexpectedPlaceholder()
  3. 11.x core/tests/Drupal/Tests/Component/Render/FormattableMarkupTest.php \Drupal\Tests\Component\Render\FormattableMarkupTest::testUnexpectedPlaceholder()

@covers ::__toString @dataProvider providerTestUnexpectedPlaceholder

File

core/tests/Drupal/Tests/Component/Render/FormattableMarkupTest.php, line 99

Class

FormattableMarkupTest
Tests the TranslatableMarkup class.

Namespace

Drupal\Tests\Component\Render

Code

public function testUnexpectedPlaceholder($string, $arguments, $error_number, $error_message) {
    // We set a custom error handler because of https://github.com/sebastianbergmann/phpunit/issues/487
    set_error_handler([
        $this,
        'errorHandler',
    ]);
    // We want this to trigger an error.
    $markup = new FormattableMarkup($string, $arguments);
    // Cast it to a string which will generate the errors.
    $output = (string) $markup;
    restore_error_handler();
    // The string should not change.
    $this->assertEquals($string, $output);
    $this->assertEquals($error_number, $this->lastErrorNumber);
    $this->assertEquals($error_message, $this->lastErrorMessage);
}

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