You are here

public function JsonTest::testReversibility 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::testReversibility()
  2. 9 core/tests/Drupal/Tests/Component/Serialization/JsonTest.php \Drupal\Tests\Component\Serialization\JsonTest::testReversibility()

Tests converting PHP variables to JSON strings and back.

File

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

Class

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

Namespace

Drupal\Tests\Component\Serialization

Code

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

  // Verify that encoding/decoding is reversible.
  $json_decoded = Json::decode($json);
  $this
    ->assertSame($this->string, $json_decoded, 'Encoding a string to JSON and decoding back results in the original string.');
}