Skip to content

Commit b7bbdd9

Browse files
committed
Add test to illustrate issue #17
1 parent 774783e commit b7bbdd9

1 file changed

Lines changed: 31 additions & 0 deletions

File tree

‎tests/functional/CachePoolTest.php‎

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -359,4 +359,35 @@ public function testHas()
359359
$this->assertFalse($subject->has($notThereKey));
360360
}
361361
}
362+
363+
/**
364+
* Imitates a scenario where `set_transient()` erroneously returns `false` if set value is same as existing.
365+
*/
366+
public function testWritingSameValueSucceeds()
367+
{
368+
{
369+
$poolName = uniqid('pool');
370+
$defaultValue = uniqid('default');
371+
$wpdb = $this->createWpdb();
372+
$key = uniqid('key');
373+
$value = uniqid('value');
374+
$subject = $this->createInstance($wpdb, $poolName, $defaultValue);
375+
}
376+
377+
{
378+
Functions\expect('get_transient')
379+
->andReturn($value);
380+
Functions\expect('set_transient')
381+
->andReturn();
382+
}
383+
384+
{
385+
// If no exception - success
386+
$subject->set($key, $value, rand(1, 99999));
387+
388+
// Problem setting a different value results in an exception
389+
$this->expectException(CacheException::class);
390+
$subject->set($key, uniqid('other-value'), rand(1, 99999));
391+
}
392+
}
362393
}

0 commit comments

Comments
 (0)