diff --git a/src/Symfony/Component/Cache/Adapter/NullAdapter.php b/src/Symfony/Component/Cache/Adapter/NullAdapter.php index 3c88a6902a9e..cd6a937b6c40 100644 --- a/src/Symfony/Component/Cache/Adapter/NullAdapter.php +++ b/src/Symfony/Component/Cache/Adapter/NullAdapter.php @@ -42,7 +42,7 @@ function ($key) { */ public function get(string $key, callable $callback, float $beta = null, array &$metadata = null) { - return $callback(($this->createCacheItem)()); + return $callback(($this->createCacheItem)($key)); } /** diff --git a/src/Symfony/Component/Cache/Tests/Adapter/NullAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/NullAdapterTest.php index 73e5cad5529a..7dd08ad865fa 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/NullAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/NullAdapterTest.php @@ -34,6 +34,19 @@ public function testGetItem() $this->assertNull($item->get(), "Item's value must be null when isHit is false."); } + public function testGet() + { + $adapter = $this->createCachePool(); + + $fetched = []; + $item = $adapter->get('myKey', function ($item) use (&$fetched) { $fetched[] = $item; }); + $this->assertCount(1, $fetched); + $item = $fetched[0]; + $this->assertFalse($item->isHit()); + $this->assertNull($item->get(), "Item's value must be null when isHit is false."); + $this->assertSame('myKey', $item->getKey()); + } + public function testHasItem() { $this->assertFalse($this->createCachePool()->hasItem('key'));