8000 bug #29794 Always pass $key to NullAdapter->createCacheItem (TysonAndre) · symfony/symfony@968e736 · GitHub
[go: up one dir, main page]

Skip to content

Commit 968e736

Browse files
bug #29794 Always pass $key to NullAdapter->createCacheItem (TysonAndre)
This PR was merged into the 4.2 branch. Discussion ---------- Always pass $key to NullAdapter->createCacheItem | Q | A | ------------- | --- | Branch? | 4.2 | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes (build failure seems unrelated) | Fixed tickets | | License | MIT | Doc PR | 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 Commits ------- 1976d29 Always pass $key to NullAdapter->createCacheItem
2 parents f7b9bb2 + 1976d29 commit 968e736

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Symfony/Component/Cache/Adapter/NullAdapter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ function ($key) {
4242
*/
4343
public function get(string $key, callable $callback, float $beta = null, array &$metadata = null)
4444
{
45-
return $callback(($this->createCacheItem)());
45+
return $callback(($this->createCacheItem)($key));
4646
}
4747

4848
/**

src/Symfony/Component/Cache/Tests/Adapter/NullAdapterTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,19 @@ public function testGetItem()
3434
$this->assertNull($item->get(), "Item's value must be null when isHit is false.");
3535
}
3636

37+
public function testGet()
38+
{
39+
$adapter = $this->createCachePool();
40+
41+
$fetched = [];
42+
$item = $adapter->get('myKey', function ($item) use (&$fetched) { $fetched[] = $item; });
43+
$this->assertCount(1, $fetched);
44+
$item = $fetched[0];
45+
$this->assertFalse($item->isHit());
46+
$this->assertNull($item->get(), "Item's value must be null when isHit is false.");
47+
$this->assertSame('myKey', $item->getKey());
48+
}
49+
3750
public function testHasItem()
3851
{
3952
$this->assertFalse($this->createCachePool()->hasItem('key'));

0 commit comments

Comments
 (0)
0