diff --git a/core/lib/Drupal/Core/Cache/BackendChain.php b/core/lib/Drupal/Core/Cache/BackendChain.php index 3b3489af9d..8e02656eed 100644 --- a/core/lib/Drupal/Core/Cache/BackendChain.php +++ b/core/lib/Drupal/Core/Cache/BackendChain.php @@ -30,12 +30,18 @@ class BackendChain implements CacheBackendInterface, CacheTagsInvalidatorInterfa protected $backends = []; /** - * Constructs a DatabaseBackend object. + * Constructs a new backend chain service instance. * - * @param string $bin - * The cache bin for which the object is created. + * @param string|null $bin + * (deprecated) The cache bin for which the object is created. The $bin + * parameter is deprecated in drupal:8.8.0 and is removed from drupal:9.0.0. + * + * @see https://www.drupal.org/node/3061125 */ - public function __construct($bin) { + public function __construct($bin = NULL) { + if ($bin) { + @trigger_error('The $bin parameter is deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Omit the first parameter. See https://www.drupal.org/node/3061125', E_USER_DEPRECATED); + } } /** diff --git a/core/tests/Drupal/KernelTests/Core/Cache/BackendChainTest.php b/core/tests/Drupal/KernelTests/Core/Cache/BackendChainTest.php index 72c0de99f0..5cdc413346 100644 --- a/core/tests/Drupal/KernelTests/Core/Cache/BackendChainTest.php +++ b/core/tests/Drupal/KernelTests/Core/Cache/BackendChainTest.php @@ -13,7 +13,7 @@ class BackendChainTest extends GenericCacheBackendUnitTestBase { protected function createCacheBackend($bin) { - $chain = new BackendChain($bin); + $chain = new BackendChain(); // We need to create some various backends in the chain. $chain diff --git a/core/tests/Drupal/Tests/Core/Cache/BackendChainImplementationUnitTest.php b/core/tests/Drupal/Tests/Core/Cache/BackendChainImplementationUnitTest.php index 4f4f587d5b..9509cc1de4 100644 --- a/core/tests/Drupal/Tests/Core/Cache/BackendChainImplementationUnitTest.php +++ b/core/tests/Drupal/Tests/Core/Cache/BackendChainImplementationUnitTest.php @@ -11,6 +11,7 @@ * Unit test of backend chain implementation specifics. * * @group Cache + * @coversDefaultClass \Drupal\Core\Cache\BackendChain */ class BackendChainImplementationUnitTest extends UnitTestCase { @@ -72,7 +73,7 @@ protected function setUp() { $this->thirdBackend->set('t3', 33); // Create the chain. - $this->chain = new BackendChain('foobarbaz'); + $this->chain = new BackendChain(); $this->chain ->appendBackend($this->firstBackend) ->appendBackend($this->secondBackend) @@ -288,7 +289,7 @@ public function testDeleteTagsPropagation() { * Test that removing bin propagates to all backends. */ public function testRemoveBin() { - $chain = new BackendChain('foo'); + $chain = new BackendChain(); for ($i = 0; $i < 3; $i++) { $backend = $this->createMock('Drupal\Core\Cache\CacheBackendInterface'); $backend->expects($this->once())->method('removeBin'); @@ -298,4 +299,15 @@ public function testRemoveBin() { $chain->removeBin(); } + /** + * Tests deprecation of the constructor parameter. + * + * @group legacy + * @covers ::__construct + * @expectedDeprecation The $bin parameter is deprecated in drupal:8.0.0 and is removed from drupal:9.0.0. Omit the first parameter. See https://www.drupal.org/node/3061125 + */ + public function testConstructorParameterDeprecation() { + new BackendChain('arbitrary'); + } + }