From 47d0389079a1bd931ef9403376368ff67d03bc3e Mon Sep 17 00:00:00 2001 From: catch Date: Sun, 3 Mar 2024 17:05:28 +0000 Subject: [PATCH] Issue #3205480 by alexpott, andypost, Wim Leers, catch, kim.pepper, longwave: Drop PECL YAML library support in favor of only Symfony YAML (cherry picked from commit 25dc2f1480ddd83896b5cba9cd0488b9ea8abe9c) --- core/.eslintignore | 3 + .../Drupal/Component/Serialization/Yaml.php | 60 +++--- .../Component/Serialization/YamlSymfony.php | 10 + core/lib/Drupal/Core/Serialization/Yaml.php | 27 +-- core/lib/Drupal/Core/Site/Settings.php | 4 + .../ConfigSingleImportExportTest.php | 18 +- .../components/bar/bar.component.yml | 3 +- core/phpstan.neon.dist | 4 + .../Serialization/YamlSymfonyTest.php | 28 ++- .../Component/Serialization/YamlTest.php | 187 +++++------------- .../assets/default.services.yml | 3 - .../assets/profile.default.services.yml | 3 - .../Tests/Core/Serialization/YamlTest.php | 78 -------- 13 files changed, 138 insertions(+), 290 deletions(-) delete mode 100644 core/tests/Drupal/Tests/Core/Serialization/YamlTest.php diff --git a/core/.eslintignore b/core/.eslintignore index 3fbb72c37d45..1e1996ffe0b6 100644 --- a/core/.eslintignore +++ b/core/.eslintignore @@ -9,6 +9,9 @@ modules/system/tests/fixtures/HtaccessTest/access_test.yml modules/system/tests/themes/test_theme_libraries_empty/test_theme_libraries_empty.info.yml tests/Drupal/Tests/Core/Asset/library_test_files/empty.libraries.yml tests/Drupal/Tests/Core/Asset/library_test_files/invalid_file.libraries.yml +tests/Drupal/Tests/Composer/Plugin/Scaffold/fixtures/drupal-assets-fixture/assets/default.services.yml +tests/Drupal/Tests/Composer/Plugin/Scaffold/fixtures/drupal-profile/assets/profile.default.services.yml +modules/sdc/tests/themes/sdc_theme_test/components/bar/bar.component.yml # Temporary until they are brought up to standards scripts/**/* diff --git a/core/lib/Drupal/Component/Serialization/Yaml.php b/core/lib/Drupal/Component/Serialization/Yaml.php index e65facd1ae0f..cb0835eed9b3 100644 --- a/core/lib/Drupal/Component/Serialization/Yaml.php +++ b/core/lib/Drupal/Component/Serialization/Yaml.php @@ -2,37 +2,43 @@ namespace Drupal\Component\Serialization; +use Drupal\Component\Serialization\Exception\InvalidDataTypeException; +use Symfony\Component\Yaml\Dumper; +use Symfony\Component\Yaml\Parser; +use Symfony\Component\Yaml\Yaml as SymfonyYaml; + /** - * Provides a YAML serialization implementation. - * - * Proxy implementation that will choose the best library based on availability. + * Provides a YAML serialization implementation using symfony/yaml. */ class Yaml implements SerializationInterface { - /** - * The YAML implementation to use. - * - * @var \Drupal\Component\Serialization\SerializationInterface - */ - protected static $serializer; - /** * {@inheritdoc} */ public static function encode($data) { - // Instead of using \Drupal\Component\Serialization\Yaml::getSerializer(), - // always using Symfony for writing the data, to reduce the risk of having - // differences if different environments (like production and development) - // do not match in terms of what YAML implementation is available. - return YamlSymfony::encode($data); + try { + // Set the indentation to 2 to match Drupal's coding standards. + $yaml = new Dumper(2); + return $yaml->dump($data, PHP_INT_MAX, 0, SymfonyYaml::DUMP_EXCEPTION_ON_INVALID_TYPE | SymfonyYaml::DUMP_MULTI_LINE_LITERAL_BLOCK); + } + catch (\Exception $e) { + throw new InvalidDataTypeException($e->getMessage(), $e->getCode(), $e); + } } /** * {@inheritdoc} */ public static function decode($raw) { - $serializer = static::getSerializer(); - return $serializer::decode($raw); + try { + $yaml = new Parser(); + // Make sure we have a single trailing newline. A very simple config like + // 'foo: bar' with no newline will fail to parse otherwise. + return $yaml->parse($raw, SymfonyYaml::PARSE_EXCEPTION_ON_INVALID_TYPE); + } + catch (\Exception $e) { + throw new InvalidDataTypeException($e->getMessage(), $e->getCode(), $e); + } } /** @@ -44,21 +50,15 @@ class Yaml implements SerializationInterface { /** * Determines which implementation to use for parsing YAML. + * + * @deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no + * replacement. + * + * @see https://www.drupal.org/node/3415489 */ protected static function getSerializer() { - - if (!isset(static::$serializer)) { - // Use the PECL YAML extension if it is available. It has better - // performance for file reads and is YAML compliant. - if (extension_loaded('yaml')) { - static::$serializer = YamlPecl::class; - } - else { - // Otherwise, fallback to the Symfony implementation. - static::$serializer = YamlSymfony::class; - } - } - return static::$serializer; + @trigger_error('Calling ' . __METHOD__ . '() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. There is no replacement. See https://www.drupal.org/node/3415489', E_USER_DEPRECATED); + return YamlSymfony::class; } } diff --git a/core/lib/Drupal/Component/Serialization/YamlSymfony.php b/core/lib/Drupal/Component/Serialization/YamlSymfony.php index d570be1a4624..2344282b90f4 100644 --- a/core/lib/Drupal/Component/Serialization/YamlSymfony.php +++ b/core/lib/Drupal/Component/Serialization/YamlSymfony.php @@ -2,6 +2,8 @@ namespace Drupal\Component\Serialization; +@trigger_error('The ' . __NAMESPACE__ . '\YamlSymfony is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use \Drupal\Component\Serialization\Yaml instead. See https://www.drupal.org/node/3415489', E_USER_DEPRECATED); + use Drupal\Component\Serialization\Exception\InvalidDataTypeException; use Symfony\Component\Yaml\Parser; use Symfony\Component\Yaml\Dumper; @@ -9,6 +11,11 @@ use Symfony\Component\Yaml\Yaml as SymfonyYaml; /** * Default serialization for YAML using the Symfony component. + * + * @deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use + * \Drupal\Component\Serialization\Yaml instead. + * + * @see https://www.drupal.org/node/3415489 */ class YamlSymfony implements SerializationInterface { @@ -16,6 +23,7 @@ class YamlSymfony implements SerializationInterface { * {@inheritdoc} */ public static function encode($data) { + @trigger_error('Calling ' . __METHOD__ . '() 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', E_USER_DEPRECATED); try { // Set the indentation to 2 to match Drupal's coding standards. $yaml = new Dumper(2); @@ -30,6 +38,7 @@ class YamlSymfony implements SerializationInterface { * {@inheritdoc} */ public static function decode($raw) { + @trigger_error('Calling ' . __METHOD__ . '() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use \Drupal\Component\Serialization\Yaml::decode() instead. See https://www.drupal.org/node/3415489', E_USER_DEPRECATED); try { $yaml = new Parser(); // Make sure we have a single trailing newline. A very simple config like @@ -45,6 +54,7 @@ class YamlSymfony implements SerializationInterface { * {@inheritdoc} */ public static function getFileExtension() { + @trigger_error('Calling ' . __METHOD__ . '() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use \Drupal\Component\Serialization\Yaml::getFileExtension() instead. See https://www.drupal.org/node/3415489', E_USER_DEPRECATED); return 'yml'; } diff --git a/core/lib/Drupal/Core/Serialization/Yaml.php b/core/lib/Drupal/Core/Serialization/Yaml.php index 566f8cad4c8e..564fdac993d4 100644 --- a/core/lib/Drupal/Core/Serialization/Yaml.php +++ b/core/lib/Drupal/Core/Serialization/Yaml.php @@ -1,28 +1,7 @@ '', 'message' => 'The "block_interest_cohort" setting is deprecated in drupal:9.5.0. This setting should be removed from the settings file, since its usage has been removed. See https://www.drupal.org/node/3320787.', ], + 'yaml_parser_class' => [ + 'replacement' => '', + 'message' => 'The "yaml_parser_class" setting is deprecated in drupal:10.3.0. This setting should be removed from the settings file, since its usage has been removed. See https://www.drupal.org/node/3415489.', + ], ]; /** diff --git a/core/modules/config/tests/src/Functional/ConfigSingleImportExportTest.php b/core/modules/config/tests/src/Functional/ConfigSingleImportExportTest.php index 621f48d7e635..ea00319cfb50 100644 --- a/core/modules/config/tests/src/Functional/ConfigSingleImportExportTest.php +++ b/core/modules/config/tests/src/Functional/ConfigSingleImportExportTest.php @@ -192,21 +192,9 @@ EOD; ]; $this->drupalGet('admin/config/development/configuration/single/import'); $this->submitForm($edit, 'Import'); - if (extension_loaded('yaml')) { - // If the yaml extension is loaded it will work but not create the PHP - // object. - $this->assertSession()->pageTextContains('Are you sure you want to update the second test configuration?'); - $this->submitForm([], 'Confirm'); - $entity = $storage->load('second'); - $this->assertSession()->pageTextContains('The configuration was imported successfully.'); - $this->assertIsString($entity->label()); - $this->assertStringContainsString('ObjectSerialization', $entity->label(), 'Label contains serialized object'); - } - else { - // If the Symfony parser is used there will be an error. - $this->assertSession()->responseContains('The import failed with the following message:'); - $this->assertSession()->responseContains('Object support when parsing a YAML file has been disabled'); - } + // @see \Drupal\Tests\Component\Serialization\YamlSymfonyTest:: testDecodeObjectSupportDisabled() + $this->assertSession()->responseContains('The import failed with the following message:'); + $this->assertSession()->responseContains('Object support when parsing a YAML file has been disabled'); } /** diff --git a/core/modules/sdc/tests/themes/sdc_theme_test/components/bar/bar.component.yml b/core/modules/sdc/tests/themes/sdc_theme_test/components/bar/bar.component.yml index ddf77a07f5c3..b7e56e893bf7 100644 --- a/core/modules/sdc/tests/themes/sdc_theme_test/components/bar/bar.component.yml +++ b/core/modules/sdc/tests/themes/sdc_theme_test/components/bar/bar.component.yml @@ -1,2 +1 @@ -# YAML linter does not allow empty files, setting it to NULL tests the same. -null +# This file is intentionally left empty diff --git a/core/phpstan.neon.dist b/core/phpstan.neon.dist index f28e9249f514..d6f8ce3907a2 100644 --- a/core/phpstan.neon.dist +++ b/core/phpstan.neon.dist @@ -15,6 +15,10 @@ parameters: - . - ../composer + bootstrapFiles: + # Load aliases. + - lib/Drupal/Core/Serialization/Yaml.php + excludePaths: # Skip sites directory. - ../sites diff --git a/core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php b/core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php index e6c39fba3c25..21a398cfc32a 100644 --- a/core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php +++ b/core/tests/Drupal/Tests/Component/Serialization/YamlSymfonyTest.php @@ -6,15 +6,18 @@ namespace Drupal\Tests\Component\Serialization; use Drupal\Component\Serialization\Exception\InvalidDataTypeException; use Drupal\Component\Serialization\YamlSymfony; +use Symfony\Bridge\PhpUnit\ExpectDeprecationTrait; /** * Tests the YamlSymfony serialization implementation. * * @group Drupal * @group Serialization + * @group legacy * @coversDefaultClass \Drupal\Component\Serialization\YamlSymfony */ class YamlSymfonyTest extends YamlTestBase { + use ExpectDeprecationTrait; /** * Tests encoding and decoding basic data structures. @@ -24,6 +27,8 @@ class YamlSymfonyTest extends YamlTestBase { * @dataProvider providerEncodeDecodeTests */ public function testEncodeDecode($data) { + $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->expectDeprecation("Calling Drupal\Component\Serialization\YamlSymfony::decode() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use \Drupal\Component\Serialization\Yaml::decode() instead. See https://www.drupal.org/node/3415489"); $this->assertEquals($data, YamlSymfony::decode(YamlSymfony::encode($data))); } @@ -34,6 +39,7 @@ class YamlSymfonyTest extends YamlTestBase { * @dataProvider providerDecodeTests */ public function testDecode($string, $data) { + $this->expectDeprecation("Calling Drupal\Component\Serialization\YamlSymfony::decode() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use \Drupal\Component\Serialization\Yaml::decode() instead. See https://www.drupal.org/node/3415489"); $this->assertEquals($data, YamlSymfony::decode($string)); } @@ -43,6 +49,7 @@ class YamlSymfonyTest extends YamlTestBase { * @covers ::encode */ public function testEncode() { + $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"); // cSpell:disable $this->assertEquals('foo: bar: \'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus sapien ex, venenatis vitae nisi eu, posuere luctus dolor. Nullam convallis\' @@ -54,6 +61,7 @@ class YamlSymfonyTest extends YamlTestBase { * @covers ::getFileExtension */ public function testGetFileExtension() { + $this->expectDeprecation("Calling Drupal\Component\Serialization\YamlSymfony::getFileExtension() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use \Drupal\Component\Serialization\Yaml::getFileExtension() instead. See https://www.drupal.org/node/3415489"); $this->assertEquals('yml', YamlSymfony::getFileExtension()); } @@ -63,6 +71,7 @@ class YamlSymfonyTest extends YamlTestBase { * @covers ::decode */ public function testError() { + $this->expectDeprecation("Calling Drupal\Component\Serialization\YamlSymfony::decode() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use \Drupal\Component\Serialization\Yaml::decode() instead. See https://www.drupal.org/node/3415489"); $this->expectException(InvalidDataTypeException::class); YamlSymfony::decode('foo: [ads'); } @@ -72,7 +81,8 @@ class YamlSymfonyTest extends YamlTestBase { * * @covers ::encode */ - public function testObjectSupportDisabled() { + 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(); @@ -80,4 +90,20 @@ class YamlSymfonyTest extends YamlTestBase { YamlSymfony::encode([$object]); } + /** + * Ensures that decoding PHP objects does not work in Symfony. + * + * @covers ::decode + */ + public function testDecodeObjectSupportDisabled(): void { + $this->expectDeprecation("Calling Drupal\Component\Serialization\YamlSymfony::decode() is deprecated in drupal:10.3.0 and is removed from drupal:11.0.0. Use \Drupal\Component\Serialization\Yaml::decode() instead. See https://www.drupal.org/node/3415489"); + $this->expectException(InvalidDataTypeException::class); + $this->expectExceptionMessageMatches('/^Object support when parsing a YAML file has been disabled/'); + $yaml = <<mockParser = $this->getMockBuilder('\stdClass') - ->addMethods(['encode', 'decode', 'getFileExtension']) - ->getMock(); - YamlParserProxy::setMock($this->mockParser); - } - - /** - * {@inheritdoc} - */ - protected function tearDown(): void { - YamlParserProxy::setMock(NULL); - parent::tearDown(); - } +class YamlTest extends YamlTestBase { /** + * Tests encoding and decoding basic data structures. + * + * @covers ::encode * @covers ::decode + * @dataProvider providerEncodeDecodeTests */ - public function testDecode() { - $this->mockParser - ->expects($this->once()) - ->method('decode'); - YamlStub::decode('test'); + public function testEncodeDecode($data) { + $this->assertSame($data, Yaml::decode(Yaml::encode($data))); + } + + /** + * Tests decoding YAML node anchors. + * + * @covers ::decode + * @dataProvider providerDecodeTests + */ + public function testDecode($string, $data) { + $this->assertSame($data, Yaml::decode($string)); + } + + /** + * Tests our encode settings. + * + * @covers ::encode + */ + public function testEncode() { + // cSpell:disable + $this->assertSame('foo: + bar: \'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus sapien ex, venenatis vitae nisi eu, posuere luctus dolor. Nullam convallis\' +', Yaml::encode(['foo' => ['bar' => 'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus sapien ex, venenatis vitae nisi eu, posuere luctus dolor. Nullam convallis']])); + // cSpell:enable } /** * @covers ::getFileExtension */ public function testGetFileExtension() { - $this->mockParser - ->expects($this->never()) - ->method('getFileExtension'); - $this->assertEquals('yml', YamlStub::getFileExtension()); + $this->assertSame('yml', Yaml::getFileExtension()); } /** - * Tests all YAML files are decoded in the same way with Symfony and PECL. + * Tests that invalid YAML throws an exception. * - * This test is a little bit slow but it tests that we do not have any bugs in - * our YAML that might not be decoded correctly in any of our implementations. - * - * @todo This should exist as an integration test not part of our unit tests. - * https://www.drupal.org/node/2597730 - * - * @requires extension yaml - * @dataProvider providerYamlFilesInCore + * @covers ::decode */ - public function testYamlFiles($file) { - $data = file_get_contents($file); - try { - $this->assertEquals(YamlSymfony::decode($data), YamlPecl::decode($data), $file); - } - catch (InvalidDataTypeException $e) { - // Provide file context to the failure so the exception message is useful. - $this->fail("Exception thrown parsing $file:\n" . $e->getMessage()); - } + public function testError() { + $this->expectException(InvalidDataTypeException::class); + Yaml::decode('foo: [ads'); } /** - * Ensures that decoding php objects does not work in PECL. + * Ensures that php object support is disabled. * - * @requires extension yaml - * - * @see \Drupal\Tests\Component\Serialization\YamlTest::testObjectSupportDisabledSymfony() + * @covers ::encode */ - public function testObjectSupportDisabledPecl() { + public function testEncodeObjectSupportDisabled() { + $this->expectException(InvalidDataTypeException::class); + $this->expectExceptionMessage('Object support when dumping 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]); - $this->assertEquals(['O:8:"stdClass":1:{s:3:"foo";s:3:"bar";}'], YamlPecl::decode($yaml)); + Yaml::encode([$object]); } /** - * Ensures that decoding php objects does not work in Symfony. + * Ensures that decoding PHP objects does not work in Symfony. * - * @requires extension yaml - * - * @see \Drupal\Tests\Component\Serialization\YamlTest::testObjectSupportDisabledPecl() + * @covers ::decode */ - public function testObjectSupportDisabledSymfony() { + public function testDecodeObjectSupportDisabled() { $this->expectException(InvalidDataTypeException::class); $this->expectExceptionMessageMatches('/^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); - } + $yaml = <<getPathname(); - // Exclude core/node_modules. - if ($dir->getExtension() == 'yml' && !str_contains($pathname, '/../../../../../node_modules')) { - if (str_contains($dir->getRealPath(), 'invalid_file')) { - // There are some intentionally invalid files provided for testing - // library API behaviors, ignore them. - continue; - } - $files[] = [$dir->getRealPath()]; - } - } - return $files; - } - -} - -class YamlStub extends Yaml { - - public static function getSerializer() { - return '\Drupal\Tests\Component\Serialization\YamlParserProxy'; - } - -} - -class YamlParserProxy implements SerializationInterface { - - /** - * @var \Drupal\Component\Serialization\SerializationInterface - */ - protected static $mock; - - public static function setMock($mock) { - static::$mock = $mock; - } - - public static function encode($data) { - return static::$mock->encode($data); - } - - public static function decode($raw) { - return static::$mock->decode($raw); - } - - public static function getFileExtension() { - return static::$mock->getFileExtension(); + Yaml::decode($yaml); } } diff --git a/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/fixtures/drupal-assets-fixture/assets/default.services.yml b/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/fixtures/drupal-assets-fixture/assets/default.services.yml index cc773f3e79bb..cdfdd0a9f645 100644 --- a/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/fixtures/drupal-assets-fixture/assets/default.services.yml +++ b/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/fixtures/drupal-assets-fixture/assets/default.services.yml @@ -1,4 +1 @@ # Test version of default.services.yml from drupal/core. -# Add a dummy key until YamlPecl can validate an empty YAML file: -# https://www.drupal.org/project/drupal/issues/3003300 -foo: bar diff --git a/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/fixtures/drupal-profile/assets/profile.default.services.yml b/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/fixtures/drupal-profile/assets/profile.default.services.yml index 2a35c02dbae1..e59669248ffb 100644 --- a/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/fixtures/drupal-profile/assets/profile.default.services.yml +++ b/core/tests/Drupal/Tests/Composer/Plugin/Scaffold/fixtures/drupal-profile/assets/profile.default.services.yml @@ -1,4 +1 @@ # default.services.yml fixture scaffolded from "file-mappings" in drupal-project composer.json fixture. -# Add a dummy key until YamlPecl can validate an empty YAML file: -# https://www.drupal.org/project/drupal/issues/3003300 -foo: bar diff --git a/core/tests/Drupal/Tests/Core/Serialization/YamlTest.php b/core/tests/Drupal/Tests/Core/Serialization/YamlTest.php deleted file mode 100644 index 70f488e2528e..000000000000 --- a/core/tests/Drupal/Tests/Core/Serialization/YamlTest.php +++ /dev/null @@ -1,78 +0,0 @@ - YamlParserProxy::class]); - - $this->assertEquals(YamlParserProxy::class, Settings::get('yaml_parser_class')); - - $mock = $this->getMockBuilder(YamlTestMockInterface::class) - ->onlyMethods(['decode']) - ->getMock(); - $mock - ->expects($this->once()) - ->method('decode'); - YamlParserProxy::setMock($mock); - Yaml::decode('---'); - - new Settings([]); - } - -} - -class YamlParserProxy implements SerializationInterface { - - /** - * @var \Drupal\Component\Serialization\SerializationInterface - */ - protected static $mock; - - public static function setMock($mock) { - static::$mock = $mock; - } - - public static function encode($data) { - return static::$mock->encode($data); - } - - public static function decode($raw) { - return static::$mock->decode($raw); - } - - public static function getFileExtension() { - return static::$mock->getFileExtension(); - } - -} - -/** - * Interface used in the mocking process of this test. - */ -interface YamlTestMockInterface { - - /** - * Function used in the mocking process of this test. - */ - public function decode(); - -}