Commit 47c2dda6 authored by larowlan's avatar larowlan

Issue #2927746 by alexpott, catch, slasher13, mpdonadio, martin107, RoSk0,...

Issue #2927746 by alexpott, catch, slasher13, mpdonadio, martin107, RoSk0, jibran, larowlan, pounard, Mile23, Jo Fitzgerald, deviantintegral, pritish.kumar: Update Symfony components to 3.4.*
parent 6a3ba025
This diff is collapsed.
......@@ -4,20 +4,20 @@
"type": "drupal-core",
"license": "GPL-2.0+",
"require": {
"php": ">=5.5.9",
"symfony/class-loader": "~3.2.8",
"symfony/console": "~3.2.8",
"symfony/dependency-injection": "~3.2.8",
"symfony/event-dispatcher": "~3.2.8",
"symfony/http-foundation": "~3.2.8",
"symfony/http-kernel": "~3.2.8",
"symfony/routing": "~3.2.8",
"symfony/serializer": "~3.2.8",
"symfony/translation": "~3.2.8",
"symfony/validator": "~3.2.8",
"symfony/process": "~3.2.8",
"php": "^5.5.9|>=7.0.8",
"symfony/class-loader": "~3.4.0",
"symfony/console": "~3.4.0",
"symfony/dependency-injection": "~3.4.0",
"symfony/event-dispatcher": "~3.4.0",
"symfony/http-foundation": "~3.4.0",
"symfony/http-kernel": "~3.4.0",
"symfony/routing": "~3.4.0",
"symfony/serializer": "~3.4.0",
"symfony/translation": "~3.4.0",
"symfony/validator": "~3.4.0",
"symfony/process": "~3.4.0",
"symfony/polyfill-iconv": "^1.0",
"symfony/yaml": "~3.2.8",
"symfony/yaml": "~3.4.0",
"twig/twig": "^1.35.0",
"doctrine/common": "^2.5",
"doctrine/annotations": "^1.2",
......@@ -46,8 +46,9 @@
"mikey179/vfsStream": "^1.2",
"phpunit/phpunit": "^4.8.35 || ^6.1",
"phpspec/prophecy": "^1.4",
"symfony/css-selector": "~3.2.8",
"symfony/phpunit-bridge": "^3.4.3"
"symfony/css-selector": "^3.4.0",
"symfony/phpunit-bridge": "^3.4.3",
"symfony/debug": "^3.4.0"
},
"replace": {
"drupal/action": "self.version",
......
......@@ -65,7 +65,7 @@ public function getArray() {
$definition['aliases'] = $this->getAliases();
$definition['parameters'] = $this->getParameters();
$definition['services'] = $this->getServiceDefinitions();
$definition['frozen'] = $this->container->isFrozen();
$definition['frozen'] = $this->container->isCompiled();
$definition['machine_format'] = $this->supportsMachineFormat();
return $definition;
}
......@@ -103,8 +103,8 @@ protected function getParameters() {
}
$parameters = $this->container->getParameterBag()->all();
$is_frozen = $this->container->isFrozen();
return $this->prepareParameters($parameters, $is_frozen);
$is_compiled = $this->container->isCompiled();
return $this->prepareParameters($parameters, $is_compiled);
}
/**
......@@ -309,10 +309,10 @@ protected function dumpCollection($collection, &$resolve = FALSE) {
}
}
else {
if (is_object($value)) {
$code[$key] = $this->dumpValue($value);
if (is_object($code[$key])) {
$resolve = TRUE;
}
$code[$key] = $this->dumpValue($value);
}
}
......@@ -403,6 +403,9 @@ protected function dumpValue($value) {
elseif ($value instanceof Parameter) {
return $this->getParameterCall((string) $value);
}
elseif (is_string($value) && preg_match('/^\%(.*)\%$/', $value, $matches)) {
return $this->getParameterCall($matches[1]);
}
elseif ($value instanceof Expression) {
throw new RuntimeException('Unable to use expressions as the Symfony ExpressionLanguage component is not installed.');
}
......
......@@ -104,8 +104,11 @@ public function dispatch($event_name, Event $event = NULL) {
if (!isset($definition['callable'])) {
$definition['callable'] = [$this->container->get($definition['service'][0]), $definition['service'][1]];
}
if (is_array($definition['callable']) && isset($definition['callable'][0]) && $definition['callable'][0] instanceof \Closure) {
$definition['callable'][0] = $definition['callable'][0]();
}
$definition['callable']($event, $event_name, $this);
call_user_func($definition['callable'], $event, $event_name, $this);
if ($event->isPropagationStopped()) {
return $event;
}
......@@ -144,6 +147,9 @@ public function getListeners($event_name = NULL) {
if (!isset($definition['callable'])) {
$definition['callable'] = [$this->container->get($definition['service'][0]), $definition['service'][1]];
}
if (is_array($definition['callable']) && isset($definition['callable'][0]) && $definition['callable'][0] instanceof \Closure) {
$definition['callable'][0] = $definition['callable'][0]();
}
$result[] = $definition['callable'];
}
......@@ -156,27 +162,29 @@ public function getListeners($event_name = NULL) {
/**
* {@inheritdoc}
*/
public function getListenerPriority($eventName, $listener) {
// Parts copied from \Symfony\Component\EventDispatcher, that's why you see
// a yoda condition here.
if (!isset($this->listeners[$eventName])) {
public function getListenerPriority($event_name, $listener) {
if (!isset($this->listeners[$event_name])) {
return;
}
foreach ($this->listeners[$eventName] as $priority => $listeners) {
if (FALSE !== ($key = array_search(['callable' => $listener], $listeners, TRUE))) {
return $priority;
}
if (is_array($listener) && isset($listener[0]) && $listener[0] instanceof \Closure) {
$listener[0] = $listener[0]();
}
// Resolve service definitions if the listener has not been found so far.
foreach ($this->listeners[$eventName] as $priority => &$definitions) {
foreach ($this->listeners[$event_name] as $priority => &$definitions) {
foreach ($definitions as $key => &$definition) {
if (!isset($definition['callable'])) {
// Once the callable is retrieved we keep it for subsequent method
// invocations on this class.
$definition['callable'] = [$this->container->get($definition['service'][0]), $definition['service'][1]];
if ($definition['callable'] === $listener) {
return $priority;
}
$definition['callable'] = [
$this->container->get($definition['service'][0]),
$definition['service'][1],
];
}
if (is_array($definition['callable']) && isset($definition['callable'][0]) && $definition['callable'][0] instanceof \Closure) {
$definition['callable'][0] = $definition['callable'][0]();
}
if ($definition['callable'] === $listener) {
return $priority;
}
}
}
......@@ -186,7 +194,17 @@ public function getListenerPriority($eventName, $listener) {
* {@inheritdoc}
*/
public function hasListeners($event_name = NULL) {
return (bool) count($this->getListeners($event_name));
if ($event_name !== NULL) {
return !empty($this->listeners[$event_name]);
}
foreach ($this->listeners as $event_listeners) {
if ($event_listeners) {
return TRUE;
}
}
return FALSE;
}
/**
......@@ -214,10 +232,23 @@ public function removeListener($event_name, $listener) {
$definition['callable'] = [$this->container->get($definition['service'][0]), $definition['service'][1]];
}
if (is_array($definition['callable']) && isset($definition['callable'][0]) && $definition['callable'][0] instanceof \Closure && !$listener instanceof \Closure) {
$definition['callable'][0] = $definition['callable'][0]();
}
if (is_array($definition['callable']) && isset($definition['callable'][0]) && !$definition['callable'][0] instanceof \Closure && is_array($listener) && isset($listener[0]) && $listener[0] instanceof \Closure) {
$listener[0] = $listener[0]();
}
if ($definition['callable'] === $listener) {
unset($this->listeners[$event_name][$priority][$key]);
unset($definitions[$key]);
}
}
if ($definitions) {
$this->listeners[$event_name][$priority] = $definitions;
}
else {
unset($this->listeners[$event_name][$priority]);
}
}
}
......
......@@ -34,7 +34,7 @@ public static function decode($raw) {
$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);
return $yaml->parse($raw, SymfonyYaml::PARSE_EXCEPTION_ON_INVALID_TYPE | SymfonyYaml::PARSE_KEYS_AS_STRINGS);
}
catch (\Exception $e) {
throw new InvalidDataTypeException($e->getMessage(), $e->getCode(), $e);
......
......@@ -46,9 +46,12 @@ private function getProxyInstantiator()
}
/**
* {@inheritdoc}
* A 1to1 copy of parent::shareService.
*
* @todo https://www.drupal.org/project/drupal/issues/2937010 Since Symfony
* 3.4 this is not a 1to1 copy.
*/
protected function shareService(Definition $definition, $service, $id)
protected function shareService(Definition $definition, $service, $id, array &$inlineServices)
{
if ($definition->isShared()) {
$this->services[$lowerId = strtolower($id)] = $service;
......@@ -85,7 +88,20 @@ public function register($id, $class = null) {
if (strtolower($id) !== $id) {
throw new \InvalidArgumentException("Service ID names must be lowercase: $id");
}
return parent::register($id, $class);
$definition = parent::register($id, $class);
// As of Symfony 3.4 all services are private by default.
$definition->setPublic(TRUE);
return $definition;
}
/**
* {@inheritdoc}
*/
public function setAlias($alias, $id) {
$alias = parent::setAlias($alias, $id);
// As of Symfony 3.4 all aliases are private by default.
$alias->setPublic(TRUE);
return $alias;
}
/**
......@@ -100,8 +116,11 @@ public function setParameter($name, $value) {
/**
* A 1to1 copy of parent::callMethod.
*
* @todo https://www.drupal.org/project/drupal/issues/2937010 Since Symfony
* 3.4 this is not a 1to1 copy.
*/
protected function callMethod($service, $call) {
protected function callMethod($service, $call, array &$inlineServices = array()) {
$services = self::getServiceConditionals($call[1]);
foreach ($services as $s) {
......
......@@ -8,7 +8,7 @@
use Symfony\Component\DependencyInjection\Alias;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\DependencyInjection\Definition;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\Reference;
use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
......@@ -155,9 +155,11 @@ private function parseDefinition($id, $service, $file)
}
if (isset($service['parent'])) {
$definition = new DefinitionDecorator($service['parent']);
$definition = new ChildDefinition($service['parent']);
} else {
$definition = new Definition();
// As of Symfony 3.4 all services are private by default.
$definition->setPublic(TRUE);
}
if (isset($service['class'])) {
......@@ -329,7 +331,10 @@ protected function loadFile($file)
throw new InvalidArgumentException(sprintf('The service file "%s" is not valid.', $file));
}
return $this->validate(Yaml::decode(file_get_contents($file)), $file);
// @todo Remove preg_replace() once
// https://github.com/symfony/symfony/pull/25787 is in Symfony 3.4.
$content = preg_replace('/:$\n^\s+{\s*}$/m', ': {}', file_get_contents($file));
return $this->validate(Yaml::decode($content), $file);
}
/**
......
......@@ -76,10 +76,10 @@ public function onException(GetResponseForExceptionEvent $event) {
// the configured upload limit.
if ($exception instanceof BrokenPostRequestException && $request->query->has(FormBuilderInterface::AJAX_FORM_REQUEST)) {
$this->drupalSetMessage($this->t('An unrecoverable error occurred. The uploaded file likely exceeded the maximum file size (@size) that this server supports.', ['@size' => $this->formatSize($exception->getSize())]), 'error');
$response = new AjaxResponse();
$response = new AjaxResponse(NULL, 200);
$status_messages = ['#type' => 'status_messages'];
$response->addCommand(new PrependCommand(NULL, $status_messages));
$response->headers->set('X-Status-Code', 200);
$event->allowCustomResponseCode();
$event->setResponse($response);
return;
}
......@@ -99,7 +99,8 @@ public function onException(GetResponseForExceptionEvent $event) {
// Since this response is being set in place of an exception, explicitly
// mark this as a 200 status.
$response->headers->set('X-Status-Code', 200);
$response->setStatusCode(200);
$event->allowCustomResponseCode();
$event->setResponse($response);
}
catch (\Exception $e) {
......
......@@ -59,23 +59,23 @@ public static function setSettingsOnRequest(Request $request, Settings $settings
// Initialize proxy settings.
if ($settings->get('reverse_proxy', FALSE)) {
$ip_header = $settings->get('reverse_proxy_header', 'X_FORWARDED_FOR');
$request::setTrustedHeaderName($request::HEADER_CLIENT_IP, $ip_header);
$request::setTrustedHeaderName($request::HEADER_X_FORWARDED_FOR, $ip_header);
$proto_header = $settings->get('reverse_proxy_proto_header', 'X_FORWARDED_PROTO');
$request::setTrustedHeaderName($request::HEADER_CLIENT_PROTO, $proto_header);
$request::setTrustedHeaderName($request::HEADER_X_FORWARDED_PROTO, $proto_header);
$host_header = $settings->get('reverse_proxy_host_header', 'X_FORWARDED_HOST');
$request::setTrustedHeaderName($request::HEADER_CLIENT_HOST, $host_header);
$request::setTrustedHeaderName($request::HEADER_X_FORWARDED_HOST, $host_header);
$port_header = $settings->get('reverse_proxy_port_header', 'X_FORWARDED_PORT');
$request::setTrustedHeaderName($request::HEADER_CLIENT_PORT, $port_header);
$request::setTrustedHeaderName($request::HEADER_X_FORWARDED_PORT, $port_header);
$forwarded_header = $settings->get('reverse_proxy_forwarded_header', 'FORWARDED');
$request::setTrustedHeaderName($request::HEADER_FORWARDED, $forwarded_header);
$proxies = $settings->get('reverse_proxy_addresses', []);
if (count($proxies) > 0) {
$request::setTrustedProxies($proxies);
$request::setTrustedProxies($proxies, Request::HEADER_X_FORWARDED_ALL | Request::HEADER_FORWARDED);
}
}
}
......
......@@ -120,6 +120,9 @@ protected function prepareSettings() {
// Add a listener to validate configuration schema on save.
$yaml = new SymfonyYaml();
$content = file_get_contents($directory . '/services.yml');
// @todo Remove preg_replace() once
// https://github.com/symfony/symfony/pull/25787 is in Symfony 3.4.
$content = preg_replace('/:$\n^\s+{\s*}$/m', ': {}', $content);
$services = $yaml->parse($content);
$services['services']['simpletest.config_schema_checker'] = [
'class' => ConfigSchemaChecker::class,
......@@ -165,7 +168,11 @@ protected function setContainerParameter($name, $value) {
$filename = $this->siteDirectory . '/services.yml';
chmod($filename, 0666);
$services = Yaml::decode(file_get_contents($filename));
// @todo Remove preg_replace() once
// https://github.com/symfony/symfony/pull/25787 is in Symfony 3.4.
$content = file_get_contents($filename);
$content = preg_replace('/:$\n^\s+{\s*}$/m', ': {}', $content);
$services = Yaml::decode($content);
$services['parameters'][$name] = $value;
file_put_contents($filename, Yaml::encode($services));
......
......@@ -117,6 +117,8 @@ public function testCommentPreviewDuplicateSubmission() {
// Go back and re-submit the form.
$this->getSession()->getDriver()->back();
$submit_button = $this->assertSession()->buttonExists('Save');
$submit_button->click();
$this->assertText('Your comment has been posted.');
$elements = $this->xpath('//section[contains(@class, "comment-wrapper")]/article');
$this->assertEqual(2, count($elements));
......
......@@ -172,12 +172,24 @@ public function testImport() {
'import' => $import,
];
$this->drupalPostForm('admin/config/development/configuration/single/import', $edit, t('Import'));
$this->assertRaw(t('Are you sure you want to update the %name @type?', ['%name' => 'second', '@type' => 'test configuration']));
$this->drupalPostForm(NULL, [], t('Confirm'));
$entity = $storage->load('second');
$this->assertRaw(t('The configuration was imported successfully.'));
$this->assertTrue(is_string($entity->label()), 'Entity label is a string');
$this->assertTrue(strpos($entity->label(), 'ObjectSerialization') > 0, 'Label contains serialized object');
if (extension_loaded('yaml')) {
// If the yaml extension is loaded it will work but not create the PHP
// object.
$this->assertRaw(t('Are you sure you want to update the %name @type?', [
'%name' => 'second',
'@type' => 'test configuration'
]));
$this->drupalPostForm(NULL, [], t('Confirm'));
$entity = $storage->load('second');
$this->assertRaw(t('The configuration was imported successfully.'));
$this->assertTrue(is_string($entity->label()), 'Entity label is a string');
$this->assertTrue(strpos($entity->label(), 'ObjectSerialization') > 0, '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');
}
}
/**
......
......@@ -7,7 +7,7 @@
use Drupal\rest\LinkManager\LinkManager;
use Drupal\rest\LinkManager\RelationLinkManager;
use Drupal\rest\LinkManager\TypeLinkManager;
use Symfony\Component\DependencyInjection\DefinitionDecorator;
use Symfony\Component\DependencyInjection\ChildDefinition;
use Symfony\Component\DependencyInjection\Reference;
/**
......@@ -28,21 +28,21 @@ public function register(ContainerBuilder $container) {
// @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0.
// Use hal.link_manager instead.
// @see https://www.drupal.org/node/2830467
$service_definition = new DefinitionDecorator(new Reference('hal.link_manager'));
$service_definition = new ChildDefinition(new Reference('hal.link_manager'));
$service_definition->setClass(LinkManager::class);
$container->setDefinition('rest.link_manager', $service_definition);
// @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0.
// Use hal.link_manager.type instead.
// @see https://www.drupal.org/node/2830467
$service_definition = new DefinitionDecorator(new Reference('hal.link_manager.type'));
$service_definition = new ChildDefinition(new Reference('hal.link_manager.type'));
$service_definition->setClass(TypeLinkManager::class);
$container->setDefinition('rest.link_manager.type', $service_definition);
// @deprecated in Drupal 8.3.x and will be removed before Drupal 9.0.0.
// Use hal.link_manager.relation instead.
// @see https://www.drupal.org/node/2830467
$service_definition = new DefinitionDecorator(new Reference('hal.link_manager.relation'));
$service_definition = new ChildDefinition(new Reference('hal.link_manager.relation'));
$service_definition->setClass(RelationLinkManager::class);
$container->setDefinition('rest.link_manager.relation', $service_definition);
}
......
......@@ -67,9 +67,15 @@ public function testArrayArgumentsSQLInjection() {
public function testConditionOperatorArgumentsSQLInjection() {
$injection = "IS NOT NULL) ;INSERT INTO {test} (name) VALUES ('test12345678'); -- ";
// Convert errors to exceptions for testing purposes below.
set_error_handler(function ($severity, $message, $filename, $lineno) {
throw new \ErrorException($message, 0, $severity, $filename, $lineno);
$previous_error_handler = set_error_handler(function ($severity, $message, $filename, $lineno, $context) use (&$previous_error_handler) {
// Normalize the filename to use UNIX directory separators.
if (preg_match('@core/lib/Drupal/Core/Database/Query/Condition.php$@', str_replace(DIRECTORY_SEPARATOR, '/', $filename))) {
// Convert errors to exceptions for testing purposes below.
throw new \ErrorException($message, 0, $severity, $filename, $lineno);
}
if ($previous_error_handler) {
return $previous_error_handler($severity, $message, $filename, $lineno, $context);
}
});
try {
$result = db_select('test', 't')
......
......@@ -68,7 +68,7 @@ protected function setUp() {
$this->containerBuilder->getAliases()->willReturn([]);
$this->containerBuilder->getParameterBag()->willReturn(new ParameterBag());
$this->containerBuilder->getDefinitions()->willReturn(NULL);
$this->containerBuilder->isFrozen()->willReturn(TRUE);
$this->containerBuilder->isCompiled()->willReturn(TRUE);
$definition = [];
$definition['aliases'] = [];
......@@ -147,7 +147,7 @@ public function testGetParameters($parameters, $definition_parameters, $is_froze
$parameter_bag = new ParameterBag($parameters);
$this->containerBuilder->getParameterBag()->willReturn($parameter_bag);
$this->containerBuilder->isFrozen()->willReturn($is_frozen);
$this->containerBuilder->isCompiled()->willReturn($is_frozen);
if (isset($parameters['reference'])) {
$definition = new Definition('\stdClass');
......
......@@ -193,4 +193,59 @@ public function testGetListenerPriorityWithServices()
$this->assertSame(5, $actualPriority);
}
/**
* @expectedDeprecation The Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher class is deprecated since Symfony 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.
* @group legacy
*/
public function testAddAListenerService() {
parent::testAddAListenerService();
}
/**
* @expectedDeprecation The Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher class is deprecated since Symfony 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.
* @group legacy
*/
public function testPreventDuplicateListenerService() {
parent::testPreventDuplicateListenerService();
}
/**
* @expectedDeprecation The Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher class is deprecated since Symfony 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.
* @group legacy
*/
public function testAddASubscriberService() {
parent::testAddASubscriberService();
}
/**
* @expectedDeprecation The Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher class is deprecated since Symfony 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.
* @group legacy
*/
public function testHasListenersOnLazyLoad() {
parent::testHasListenersOnLazyLoad();
}
/**
* @expectedDeprecation The Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher class is deprecated since Symfony 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.
* @group legacy
*/
public function testGetListenersOnLazyLoad() {
parent::testGetListenersOnLazyLoad();
}
/**
* @expectedDeprecation The Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher class is deprecated since Symfony 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.
* @group legacy
*/
public function testRemoveAfterDispatch() {
parent::testRemoveAfterDispatch();
}
/**
* @expectedDeprecation The Symfony\Component\EventDispatcher\ContainerAwareEventDispatcher class is deprecated since Symfony 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.
* @group legacy
*/
public function testRemoveBeforeDispatch() {
parent::testRemoveBeforeDispatch();
}
}
......@@ -77,20 +77,46 @@ public function testYamlFiles($file) {
}
/**
* 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);
}
/**
......
......@@ -39,7 +39,7 @@ public function testContainerWithoutLazyServices() {
$this->proxyServicesPass->process($container);
$this->assertCount(1, $container->getDefinitions());
$this->assertCount(2, $container->getDefinitions());
$this->assertEquals('Drupal\Core\Plugin\CachedDiscoveryClearer', $container->getDefinition('plugin_cache_clearer')->getClass());
}
......@@ -53,7 +53,7 @@ public function testContainerWithLazyServices() {
$this->proxyServicesPass->process($container);
$this->assertCount(2, $container->getDefinitions());
$this->assertCount(3, $container->getDefinitions());
$non_proxy_definition = $container->getDefinition('drupal.proxy_original_service.plugin_cache_clearer');
$this->assertEquals('Drupal\Core\Plugin\CachedDiscoveryClearer', $non_proxy_definition->getClass());
......
......@@ -38,7 +38,7 @@ public function testProcessNoConsumers() {
$handler_pass = new TaggedHandlersPass();
$handler_pass->process($container);
$this->assertCount(1, $container->getDefinitions());
$this->assertCount(2, $container->getDefinitions());
$this->assertFalse($container->getDefinition('consumer_id')->hasMethodCall('addHandler'));
}
......
......@@ -61,6 +61,25 @@ public function testRegisterException() {
$container->register('Bar');
}
/**
* @covers ::register
*/
public function testRegister() {
$container = new ContainerBuilder();
$service = $container->register('bar');
$this->assertTrue($service->isPublic());
}
/**
* @covers ::setAlias
*/
public function testSetAlias() {
$container = new ContainerBuilder();
$container->register('bar');
$alias = $container->setAlias('foo', 'bar');
$this->assertTrue($alias->isPublic());
}
/**
* Tests serialization.
*/
......
......@@ -28,6 +28,9 @@ public function testParseDefinitionsWithProvider() {
services:
example_service:
class: \Drupal\Core\ExampleClass
example_private_service:
class: \Drupal\Core\ExampleClass
public: false
YAML;
vfsStream::setup('drupal', NULL, [
......@@ -39,6 +42,11 @@ class: \Drupal\Core\ExampleClass
$yaml_file_loader->load('vfs://drupal/modules/example/example.yml');
$this->assertEquals(['_provider' => [['provider' => 'example']]], $builder->getDefinition('example_service')->getTags());
$this->assertTrue($builder->getDefinition('example_service')->isPublic());
$this->assertFalse($builder->getDefinition('example_private_service')->isPublic());
$builder->compile();
$this->assertTrue($builder->has('example_service'));
$this->assertFalse($builder->has('example_private_service'));
}
}
......@@ -76,7 +76,8 @@ public function testOnException() {
->willReturn($response);
$event = $this->assertResponseFromException