diff --git a/core/lib/Drupal/Core/TempStore/SharedTempStore.php b/core/lib/Drupal/Core/TempStore/SharedTempStore.php index e064d7d97f..08d7fb3e60 100644 --- a/core/lib/Drupal/Core/TempStore/SharedTempStore.php +++ b/core/lib/Drupal/Core/TempStore/SharedTempStore.php @@ -112,7 +112,7 @@ public function __construct(KeyValueStoreExpirableInterface $storage, LockBacken $this->currentUser = $current_user; } else { - @trigger_error(__CLASS__ . '::__construct() now requires the current_user service to be injected. See https://www.drupal.org/node/3006268', E_USER_DEPRECATED); + @trigger_error('Calling ' . __METHOD__ . '() without the $current_user argument is deprecated in drupal:9.1.0 and will be required in drupal:10.0.0. See https://www.drupal.org/node/3006268', E_USER_DEPRECATED); $this->currentUser = \Drupal::currentUser(); if (is_int($current_user)) { // If the $current_user argument is numeric then this object has been diff --git a/core/lib/Drupal/Core/TempStore/SharedTempStoreFactory.php b/core/lib/Drupal/Core/TempStore/SharedTempStoreFactory.php index 98ce7efa4b..c8be2fecc7 100644 --- a/core/lib/Drupal/Core/TempStore/SharedTempStoreFactory.php +++ b/core/lib/Drupal/Core/TempStore/SharedTempStoreFactory.php @@ -41,13 +41,6 @@ class SharedTempStoreFactory { */ protected $currentUser; - /** - * The session service. - * - * @var \Symfony\Component\HttpFoundation\Session\SessionInterface - */ - protected $session; - /** * The time to live for items in seconds. * @@ -80,7 +73,7 @@ public function __construct(KeyValueExpirableFactoryInterface $storage_factory, $this->currentUser = \Drupal::currentUser(); } if (!($current_user instanceof AccountProxyInterface)) { - @trigger_error(__CLASS__ . '::__construct() now requires the current_user to be injected. See https://www.drupal.org/node/3006268', E_USER_DEPRECATED); + @trigger_error('Calling ' . __METHOD__ . '() without the $current_user argument is deprecated in drupal:9.1.0 and will be required in drupal:10.0.0. See https://www.drupal.org/node/3006268', E_USER_DEPRECATED); if (is_int($current_user)) { // If the $current_user argument is numeric then this object has been // instantiated with the old constructor signature. diff --git a/core/tests/Drupal/Tests/Core/TempStore/SharedTempStoreTest.php b/core/tests/Drupal/Tests/Core/TempStore/SharedTempStoreTest.php index f5ffb8ae21..c8498aa035 100644 --- a/core/tests/Drupal/Tests/Core/TempStore/SharedTempStoreTest.php +++ b/core/tests/Drupal/Tests/Core/TempStore/SharedTempStoreTest.php @@ -3,8 +3,10 @@ namespace Drupal\Tests\Core\TempStore; use Drupal\Core\DependencyInjection\ContainerBuilder; +use Drupal\Core\KeyValueStore\KeyValueExpirableFactoryInterface; use Drupal\Core\Session\AccountProxyInterface; use Drupal\Core\TempStore\Lock; +use Drupal\Core\TempStore\SharedTempStoreFactory; use Drupal\Tests\UnitTestCase; use Drupal\Core\TempStore\SharedTempStore; use Drupal\Core\TempStore\TempStoreException; @@ -391,7 +393,7 @@ public function testSerialization() { /** * @group legacy - * @expectedDeprecation Drupal\Core\TempStore\SharedTempStore::__construct() now requires the current_user service to be injected. See https://www.drupal.org/node/3006268 + * @expectedDeprecation Calling Drupal\Core\TempStore\SharedTempStore::__construct() without the $current_user argument is deprecated in drupal:9.1.0 and will be required in drupal:10.0.0. See https://www.drupal.org/node/3006268 */ public function testLegacyConstructor() { $container = new ContainerBuilder(); @@ -410,4 +412,27 @@ public function testLegacyConstructor() { $this->assertSame(1000, $expire_property->getValue($store)); } + /** + * @group legacy + * @expectedDeprecation Calling Drupal\Core\TempStore\SharedTempStoreFactory::__construct() without the $current_user argument is deprecated in drupal:9.1.0 and will be required in drupal:10.0.0. See https://www.drupal.org/node/3006268 + * @covers \Drupal\Core\TempStore\SharedTempStoreFactory::__construct + */ + public function testLegacyFactoryConstructor() { + $container = new ContainerBuilder(); + $current_user = $this->createMock(AccountProxyInterface::class); + $container->set('current_user', $current_user); + \Drupal::setContainer($container); + $key_value_factory = $this->prophesize(KeyValueExpirableFactoryInterface::class); + $store = new SharedTempStoreFactory($key_value_factory->reveal(), $this->lock, $this->requestStack, 1000); + $reflection_class = new \ReflectionClass(SharedTempStoreFactory::class); + + $current_user_property = $reflection_class->getProperty('currentUser'); + $current_user_property->setAccessible(TRUE); + $this->assertSame($current_user, $current_user_property->getValue($store)); + + $expire_property = $reflection_class->getProperty('expire'); + $expire_property->setAccessible(TRUE); + $this->assertSame(1000, $expire_property->getValue($store)); + } + }