diff --git a/src/Symfony/Component/Cache/Adapter/NullAdapter.php b/src/Symfony/Component/Cache/Adapter/NullAdapter.php index 50f2d68a66b2..f1bdd2bf7191 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 b771fa0ed83d..6c5710a7e4e2 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'));