Skip to content

Commit

Permalink
Add test to illustrate issue #17
Browse files Browse the repository at this point in the history
  • Loading branch information
XedinUnknown committed Oct 13, 2023
1 parent 774783e commit b7bbdd9
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions tests/functional/CachePoolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -359,4 +359,35 @@ public function testHas()
$this->assertFalse($subject->has($notThereKey));
}
}

/**
* Imitates a scenario where `set_transient()` erroneously returns `false` if set value is same as existing.
*/
public function testWritingSameValueSucceeds()
{
{
$poolName = uniqid('pool');
$defaultValue = uniqid('default');
$wpdb = $this->createWpdb();
$key = uniqid('key');
$value = uniqid('value');
$subject = $this->createInstance($wpdb, $poolName, $defaultValue);
}

{
Functions\expect('get_transient')
->andReturn($value);
Functions\expect('set_transient')
->andReturn();
}

{
// If no exception - success
$subject->set($key, $value, rand(1, 99999));

// Problem setting a different value results in an exception
$this->expectException(CacheException::class);
$subject->set($key, uniqid('other-value'), rand(1, 99999));
}
}
}

0 comments on commit b7bbdd9

Please sign in to comment.