function YamlSymfonyTest::testEncodeObjectSupportDisabled

Same name in other branches
  1. 10 core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php \Drupal\Tests\Component\Serialization\YamlSymfonyTest::testEncodeObjectSupportDisabled()

Ensures that php object support is disabled.

@covers ::encode

File

core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php, line 85

Class

YamlSymfonyTest
Tests the YamlSymfony serialization implementation.

Namespace

Drupal\Tests\Component\Serialization

Code

public function testEncodeObjectSupportDisabled() {
    $this->expectDeprecation("Calling Drupal\\Component\\Serialization\\YamlSymfony::encode() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use \\Drupal\\Component\\Serialization\\Yaml::encode() instead. See https://www.drupal.org/node/3415489");
    $this->expectException(InvalidDataTypeException::class);
    $this->expectExceptionMessage('Object support when dumping a YAML file has been disabled.');
    $object = new \stdClass();
    $object->foo = 'bar';
    YamlSymfony::encode([
        $object,
    ]);
}

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