function YamlTest::testObjectSupportDisabledPecl

Same name and namespace in other branches
  1. 8.9.x core/tests/Drupal/Tests/Component/Serialization/YamlTest.php \Drupal\Tests\Component\Serialization\YamlTest::testObjectSupportDisabledPecl()

Ensures that decoding php objects does not work in PECL.

@requires extension yaml

See also

\Drupal\Tests\Component\Serialization\YamlTest::testObjectSupportDisabledSymfony()

File

core/tests/Drupal/Tests/Component/Serialization/YamlTest.php, line 92

Class

YamlTest
@coversDefaultClass \Drupal\Component\Serialization\Yaml[[api-linebreak]] @group Serialization

Namespace

Drupal\Tests\Component\Serialization

Code

public function testObjectSupportDisabledPecl() {
  $object = new \stdClass();
  $object->foo = 'bar';
  // In core all Yaml encoding is done via Symfony and it does not support
  // objects so in order to encode an object we have to use the PECL
  // extension.
  // @see \Drupal\Component\Serialization\Yaml::encode()
  $yaml = YamlPecl::encode([
    $object,
  ]);
  $this->assertEquals([
    'O:8:"stdClass":1:{s:3:"foo";s:3:"bar";}',
  ], YamlPecl::decode($yaml));
}

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