You are here

public function FormattableMarkupTest::testUnexpectedPlaceholder in Drupal 8

Same name and namespace in other branches
  1. 9 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 73

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