From 33e0ba310d2d0ef93c4d52960249dd26575e623b Mon Sep 17 00:00:00 2001
From: Lee Rowlands <lee.rowlands@previousnext.com.au>
Date: Mon, 5 Feb 2018 07:42:49 +1000
Subject: [PATCH] Issue #2940956 by alexpott: Properly disable resource
 tracking in the ContainerBuilder

---
 .../DependencyInjection/ContainerBuilder.php  |  2 +-
 .../ContainerBuilderTest.php                  | 23 +++++++++++++++++++
 2 files changed, 24 insertions(+), 1 deletion(-)

diff --git a/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php b/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php
index ae3e57a67ee8..9f510781fbb5 100644
--- a/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php
+++ b/core/lib/Drupal/Core/DependencyInjection/ContainerBuilder.php
@@ -27,8 +27,8 @@ class ContainerBuilder extends SymfonyContainerBuilder {
    * {@inheritdoc}
    */
   public function __construct(ParameterBagInterface $parameterBag = NULL) {
-    $this->setResourceTracking(FALSE);
     parent::__construct($parameterBag);
+    $this->setResourceTracking(FALSE);
   }
 
   /**
diff --git a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php
index 51629a5aabff..e8de5ecf59ac 100644
--- a/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php
+++ b/core/tests/Drupal/Tests/Core/DependencyInjection/ContainerBuilderTest.php
@@ -118,4 +118,27 @@ public function testSerialize() {
     serialize($container);
   }
 
+  /**
+   * Tests constructor and resource tracking disabling.
+   *
+   * This test runs in a separate process to ensure the aliased class does not
+   * affect any other tests.
+   *
+   * @runInSeparateProcess
+   * @preserveGlobalState disabled
+   */
+  public function testConstructor() {
+    class_alias(testInterface::class, 'Symfony\Component\Config\Resource\ResourceInterface');
+    $container = new ContainerBuilder();
+    $this->assertFalse($container->isTrackingResources());
+  }
+
+}
+
+/**
+ * A test interface for testing ContainerBuilder::__construct().
+ *
+ * @see \Drupal\Tests\Core\DependencyInjection\ContainerBuilderTest::testConstructor()
+ */
+interface testInterface {
 }
-- 
GitLab