Skip to content
Permalink
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
  • Loading branch information...
nicolas-grekas committed Jan 25, 2019
2 parents f7b9bb2 + 1976d29 commit 968e7363e1025bff7cac5b8d50b87e0b4b7b78ed
@@ -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));
}
/**
@@ -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'));

0 comments on commit 968e736

Please sign in to comment.
You can’t perform that action at this time.