Skip to content

Commit

Permalink
Always pass $key to NullAdapter->createCacheItem
Browse files Browse the repository at this point in the history
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
  • Loading branch information
TysonAndre committed Jan 5, 2019
1 parent b309344 commit 1976d29
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Symfony/Component/Cache/Adapter/NullAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

/**
Expand Down
13 changes: 13 additions & 0 deletions src/Symfony/Component/Cache/Tests/Adapter/NullAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));
Expand Down

0 comments on commit 1976d29

Please sign in to comment.