Skip to content

Commit 520338e

Browse files
julien-maitanprisis
authored andcommitted
Fix missing tag warning error (#191)
Fix undefined index notice
1 parent fe5da95 commit 520338e

File tree

2 files changed

+25
-3
lines changed

2 files changed

+25
-3
lines changed

ArrayCachePool.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -197,9 +197,11 @@ protected function appendListItem($name, $key)
197197
*/
198198
protected function removeListItem($name, $key)
199199
{
200-
foreach ($this->cache[$name] as $i => $item) {
201-
if ($item === $key) {
202-
unset($this->cache[$name][$i]);
200+
if (isset($this->cache[$name])) {
201+
foreach ($this->cache[$name] as $i => $item) {
202+
if ($item === $key) {
203+
unset($this->cache[$name][$i]);
204+
}
203205
}
204206
}
205207
}

Tests/ArrayCachePoolTest.php

+20
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,24 @@ public function testLimit()
4949
$this->assertTrue($pool->hasItem('key3'));
5050
$this->assertTrue($pool->hasItem('key4'));
5151
}
52+
53+
public function testRemoveListItem()
54+
{
55+
$pool = new ArrayCachePool();
56+
$reflection = new \ReflectionClass(get_class($pool));
57+
$method = $reflection->getMethod('removeListItem');
58+
$method->setAccessible(true);
59+
60+
// Add a tagged item to test list removal
61+
$item = $pool->getItem('key1')->set('value1')->setTags(['tag1']);
62+
$pool->save($item);
63+
64+
$this->assertTrue($pool->hasItem('key1'));
65+
$this->assertTrue($pool->deleteItem('key1'));
66+
$this->assertFalse($pool->hasItem('key1'));
67+
68+
// Trying to remove an item in an un-existing tag list should not throw
69+
// Notice error / Exception in strict mode
70+
$this->assertNull($method->invokeArgs($pool, ['tag1', 'key1']));
71+
}
5272
}

0 commit comments

Comments
 (0)