You are here

public function YamlTest::testObjectSupportDisabledSymfony in Drupal 8

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

Ensures that decoding php objects does not work in Symfony.

@requires extension yaml

See also

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

File

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

Class

YamlTest
@coversDefaultClass \Drupal\Component\Serialization\Yaml @group Serialization

Namespace

Drupal\Tests\Component\Serialization

Code

public function testObjectSupportDisabledSymfony() {
  $this
    ->expectException(InvalidDataTypeException::class);
  $this
    ->expectExceptionMessageRegExp('/^Object support when parsing a YAML file has been disabled/');
  $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,
  ]);
  YamlSymfony::decode($yaml);
}