You are here

public function LogMessageParserTest::providerTestParseMessagePlaceholders in Drupal 9

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Core/Logger/LogMessageParserTest.php \Drupal\Tests\Core\Logger\LogMessageParserTest::providerTestParseMessagePlaceholders()

Data provider for testParseMessagePlaceholders().

File

core/tests/Drupal/Tests/Core/Logger/LogMessageParserTest.php, line 39

Class

LogMessageParserTest
@coversDefaultClass \Drupal\Core\Logger\LogMessageParser @group Logger

Namespace

Drupal\Tests\Core\Logger

Code

public function providerTestParseMessagePlaceholders() {
  return [
    // PSR3 only message.
    [
      [
        'message' => 'User {username} created',
        'context' => [
          'username' => 'Dries',
        ],
      ],
      [
        'message' => 'User @username created',
        'context' => [
          '@username' => 'Dries',
        ],
      ],
    ],
    // PSR3 style mixed in a format_string style message.
    [
      [
        'message' => 'User {username} created @time',
        'context' => [
          'username' => 'Dries',
          '@time' => 'now',
        ],
      ],
      [
        'message' => 'User @username created @time',
        'context' => [
          '@username' => 'Dries',
          '@time' => 'now',
        ],
      ],
    ],
    // format_string style message only.
    [
      [
        'message' => 'User @username created',
        'context' => [
          '@username' => 'Dries',
        ],
      ],
      [
        'message' => 'User @username created',
        'context' => [
          '@username' => 'Dries',
        ],
      ],
    ],
    // Message without placeholders but wildcard characters.
    [
      [
        'message' => 'User W-\\};~{&! created @',
        'context' => [
          '' => '',
        ],
      ],
      [
        'message' => 'User W-\\};~{&! created @',
        'context' => [],
      ],
    ],
    // Message with double PSR3 style messages.
    [
      [
        'message' => 'Test {with} two {encapsuled} strings',
        'context' => [
          'with' => 'together',
          'encapsuled' => 'awesome',
        ],
      ],
      [
        'message' => 'Test @with two @encapsuled strings',
        'context' => [
          '@with' => 'together',
          '@encapsuled' => 'awesome',
        ],
      ],
    ],
  ];
}