Skip to content

Commit 69a7220

Browse files
authored
[13.x] Resolve issues with tests (laravel#57258)
* cache failure 13 * session failure * Revert "cache failure 13" This reverts commit 2153795. * more tests * drop voids no where else uses it... * Update SessionStoreTest.php * bin these * spruce up the method
1 parent 1cd1d47 commit 69a7220

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/Illuminate/Cache/SessionStore.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,26 @@ public function forever($key, $value)
155155
return $this->put($key, $value, 0);
156156
}
157157

158+
/**
159+
* Adjust the expiration time of a cached item.
160+
*
161+
* @param string $key
162+
* @param int $seconds
163+
* @return bool
164+
*/
165+
public function touch($key, $seconds)
166+
{
167+
$value = $this->get($key);
168+
169+
if (is_null($value)) {
170+
return false;
171+
}
172+
173+
$this->put($key, $value, $seconds);
174+
175+
return true;
176+
}
177+
158178
/**
159179
* Remove an item from the cache.
160180
*

tests/Cache/CacheSessionStoreTest.php

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,26 @@ public function testItemsCanExpire()
7171
$this->assertNull($result);
7272
}
7373

74+
public function testTouchExtendsTtl()
75+
{
76+
Carbon::setTestNow(Carbon::now());
77+
78+
$store = new SessionStore(self::getSession());
79+
$store->put('foo', 'bar', 10);
80+
81+
// Move time forward and touch to extend TTL
82+
Carbon::setTestNow(Carbon::now()->addSeconds(5));
83+
$this->assertTrue($store->touch('foo', 60));
84+
85+
// Value should still exist past the original expiry
86+
Carbon::setTestNow(Carbon::now()->addSeconds(10));
87+
$this->assertSame('bar', $store->get('foo'));
88+
89+
// Value should expire after the new TTL
90+
Carbon::setTestNow(Carbon::now()->addSeconds(50));
91+
$this->assertNull($store->get('foo'));
92+
}
93+
7494
public function testStoreItemForeverProperlyStoresInArray()
7595
{
7696
$mock = $this->getMockBuilder(SessionStore::class)

0 commit comments

Comments
 (0)