Skip to content

Commit a5f5e39

Browse files
authored
Merge pull request #5 from mecha/fix/4_has-false-positive-expired
Fixes `has` false-positive for expired transients
2 parents 296f59c + 684b30e commit a5f5e39

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

src/CachePool.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,7 @@ public function deleteMultiple($keys)
197197
public function has($key)
198198
{
199199
$default = $this->defaultValue;
200-
$prefix = $this->getOptionNamePrefix();
201-
$value = $this->getOption("{$prefix}{$key}", $default);
200+
$value = $this->get($key, $default);
202201

203202
return $value !== $default;
204203
}

tests/functional/CachePoolTest.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -342,18 +342,16 @@ public function testHas()
342342
$defaultValue = uniqid('default');
343343
$wpdb = $this->createWpdb();
344344
$key = uniqid('key');
345-
$separator = TestSubject::NAMESPACE_SEPARATOR;
346-
$transientName = "{$poolName}{$separator}{$key}";
347-
$optionName = "_transient_$transientName";
348345
$notThereKey = uniqid('not-there');
349-
$notThereTransientName = "{$poolName}{$separator}{$notThereKey}";
350-
$notThereOptionName = "_transient_$notThereTransientName";
351-
$subject = $this->createInstance($wpdb, $poolName,$defaultValue );
346+
$subject = $this->createInstance($wpdb, $poolName, $defaultValue);
352347
}
353348

354349
{
350+
Functions\expect('get_transient')
351+
->andReturnValues([uniqid('value'), false]);
352+
355353
Functions\expect('get_option')
356-
->andReturnValues([uniqid('value'), $defaultValue]);
354+
->andReturnValues([$defaultValue]);
357355
}
358356

359357
{

0 commit comments

Comments
 (0)