Mercurial > hg > isophonics-drupal-site
diff core/tests/Drupal/Tests/Component/Serialization/YamlTest.php @ 14:1fec387a4317
Update Drupal core to 8.5.2 via Composer
author | Chris Cannam |
---|---|
date | Mon, 23 Apr 2018 09:46:53 +0100 |
parents | 4c8ae668cc8c |
children |
line wrap: on
line diff
--- a/core/tests/Drupal/Tests/Component/Serialization/YamlTest.php Mon Apr 23 09:33:26 2018 +0100 +++ b/core/tests/Drupal/Tests/Component/Serialization/YamlTest.php Mon Apr 23 09:46:53 2018 +0100 @@ -77,20 +77,46 @@ } /** - * Ensures that decoding php objects is similar for PECL and Symfony. + * Ensures that decoding php objects does not work in PECL. * * @requires extension yaml + * + * @see \Drupal\Tests\Component\Serialization\YamlTest::testObjectSupportDisabledSymfony() */ - public function testObjectSupportDisabled() { + 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 hace to use the PECL + // 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)); - $this->assertEquals(['!php/object "O:8:\"stdClass\":1:{s:3:\"foo\";s:3:\"bar\";}"'], YamlSymfony::decode($yaml)); + } + + /** + * Ensures that decoding php objects does not work in Symfony. + * + * @requires extension yaml + * + * @see \Drupal\Tests\Component\Serialization\YamlTest::testObjectSupportDisabledPecl() + */ + public function testObjectSupportDisabledSymfony() { + if (method_exists($this, 'setExpectedExceptionRegExp')) { + $this->setExpectedExceptionRegExp(InvalidDataTypeException::class, '/^Object support when parsing a YAML file has been disabled/'); + } + else { + $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); } /** @@ -101,8 +127,8 @@ $dirs = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(__DIR__ . '/../../../../../', \RecursiveDirectoryIterator::FOLLOW_SYMLINKS)); foreach ($dirs as $dir) { $pathname = $dir->getPathname(); - // Exclude vendor. - if ($dir->getExtension() == 'yml' && strpos($pathname, '/../../../../../vendor') === FALSE) { + // Exclude core/node_modules. + if ($dir->getExtension() == 'yml' && strpos($pathname, '/../../../../../node_modules') === FALSE) { if (strpos($dir->getRealPath(), 'invalid_file') !== FALSE) { // There are some intentionally invalid files provided for testing // library API behaviours, ignore them.