Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.4] handle a non existing key in array cache store #20156

Merged
merged 1 commit into from
Jul 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/Illuminate/Cache/ArrayStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ public function put($key, $value, $minutes)
*/
public function increment($key, $value = 1)
{
$this->storage[$key] = ((int) $this->storage[$key]) + $value;
$this->storage[$key] = ! isset($this->storage[$key])
? $value : ((int) $this->storage[$key]) + $value;

return $this->storage[$key];
}
Expand Down
7 changes: 7 additions & 0 deletions tests/Cache/CacheArrayStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ public function testValuesCanBeIncremented()
$this->assertEquals(2, $store->get('foo'));
}

public function testNonExistingKeysCanBeIncremented()
{
$store = new ArrayStore;
$store->increment('foo');
$this->assertEquals(1, $store->get('foo'));
}

public function testValuesCanBeDecremented()
{
$store = new ArrayStore;
Expand Down