From 471e827a0937b4406360df46310ab5fe1b30ea7b Mon Sep 17 00:00:00 2001 From: Alex Pott <alex.a.pott@googlemail.com> Date: Wed, 31 Aug 2022 09:36:37 +0100 Subject: [PATCH] Issue #3298906 by andypost, alexpott: Fix \Drupal\Tests\Core\Test\TestSetupTraitTest::testChangeDatabasePrefix() on PHP 8.2 --- core/lib/Drupal/Core/Test/TestSetupTrait.php | 14 ++++++++++++++ .../TestSite/Commands/TestSiteInstallCommand.php | 7 ------- core/tests/Drupal/Tests/BrowserTestBase.php | 14 -------------- .../Drupal/Tests/Core/Test/TestSetupTraitTest.php | 6 ++++-- 4 files changed, 18 insertions(+), 23 deletions(-) diff --git a/core/lib/Drupal/Core/Test/TestSetupTrait.php b/core/lib/Drupal/Core/Test/TestSetupTrait.php index f7ba3e0279f2..52d640094f5d 100644 --- a/core/lib/Drupal/Core/Test/TestSetupTrait.php +++ b/core/lib/Drupal/Core/Test/TestSetupTrait.php @@ -80,6 +80,20 @@ trait TestSetupTrait { */ protected $kernel; + /** + * The database prefix of this test run. + * + * @var string + */ + protected $databasePrefix; + + /** + * The app root. + * + * @var string + */ + protected $root; + /** * The temporary file directory for the test environment. * diff --git a/core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php b/core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php index e9d4349483a5..d678f6be0f1c 100644 --- a/core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php +++ b/core/tests/Drupal/TestSite/Commands/TestSiteInstallCommand.php @@ -46,13 +46,6 @@ class TestSiteInstallCommand extends Command { */ protected $timeLimit = 500; - /** - * The database prefix of this test run. - * - * @var string - */ - protected $databasePrefix; - /** * The language to install the site in. * diff --git a/core/tests/Drupal/Tests/BrowserTestBase.php b/core/tests/Drupal/Tests/BrowserTestBase.php index 229f38055b5a..cd75578c4ebe 100644 --- a/core/tests/Drupal/Tests/BrowserTestBase.php +++ b/core/tests/Drupal/Tests/BrowserTestBase.php @@ -73,13 +73,6 @@ abstract class BrowserTestBase extends TestCase { use ExpectDeprecationTrait; use ExtensionListTestTrait; - /** - * The database prefix of this test run. - * - * @var string - */ - protected $databasePrefix; - /** * Time limit in seconds for the test. * @@ -201,13 +194,6 @@ abstract class BrowserTestBase extends TestCase { */ protected $originalShutdownCallbacks = []; - /** - * The app root. - * - * @var string - */ - protected $root; - /** * The original container. * diff --git a/core/tests/Drupal/Tests/Core/Test/TestSetupTraitTest.php b/core/tests/Drupal/Tests/Core/Test/TestSetupTraitTest.php index 7b88af74511c..43dce9fdcc09 100644 --- a/core/tests/Drupal/Tests/Core/Test/TestSetupTraitTest.php +++ b/core/tests/Drupal/Tests/Core/Test/TestSetupTraitTest.php @@ -35,8 +35,10 @@ public function testChangeDatabasePrefix() { // Create a mock for testing the trait and set a few properties that are // used to avoid unnecessary set up. $test_setup = $this->getMockForTrait(TestSetupTrait::class); - $test_setup->databasePrefix = 'testDbPrefix'; - $test_setup->root = $root; + + $reflection = new \ReflectionClass($test_setup); + $reflection->getProperty('databasePrefix')->setValue($test_setup, 'testDbPrefix'); + $reflection->getProperty('root')->setValue($test_setup, $root); $method = new \ReflectionMethod(get_class($test_setup), 'changeDatabasePrefix'); $method->setAccessible(TRUE); -- GitLab