From 1976d29e014635921b61397a8e974dbe5a56ec6b Mon Sep 17 00:00:00 2001 From: Tyson Andre Date: Sat, 5 Jan 2019 10:56:34 -0500 Subject: [PATCH] Always pass $key to NullAdapter->createCacheItem Previously, if this were called, it would throw an ArgumentCountError. I'm assuming existing code always checks hasItem, so this bug hasn't impacted many people. This was noticed via static analysis. The get() method was added to NullAdapter in symfony 4.2 --- src/Symfony/Component/Cache/Adapter/NullAdapter.php | 2 +- .../Cache/Tests/Adapter/NullAdapterTest.php | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) 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'));