You are here

public function JsonTest::testEncodingStartEnd in Drupal 10

Same name and namespace in other branches
  1. 8 core/tests/Drupal/Tests/Component/Serialization/JsonTest.php \Drupal\Tests\Component\Serialization\JsonTest::testEncodingStartEnd()
  2. 9 core/tests/Drupal/Tests/Component/Serialization/JsonTest.php \Drupal\Tests\Component\Serialization\JsonTest::testEncodingStartEnd()

Tests end and start of the encoded string.

File

core/tests/Drupal/Tests/Component/Serialization/JsonTest.php, line 79

Class

JsonTest
@coversDefaultClass \Drupal\Component\Serialization\Json @group Serialization

Namespace

Drupal\Tests\Component\Serialization

Code

public function testEncodingStartEnd() {
  $json = Json::encode($this->string);

  // The first and last characters should be ", and no others.
  $this
    ->assertStringStartsWith('"', $json, 'A JSON encoded string begins with ".');
  $this
    ->assertStringEndsWith('"', $json, 'A JSON encoded string ends with ".');
  $this
    ->assertSame(2, substr_count($json, '"'), 'A JSON encoded string contains exactly two ".');
}