public function setMicrotime($microtime)
{
if (fseek($this->fileHandle, 0) !== 0) {
throw new StorageException("Could not move to beginning of the file.");
}
$data = DoublePacker::pack($microtime);
$result = fwrite($this->fileHandle, $data, strlen($data));
if ($result !== strlen($data)) {
throw new StorageException("Could not write to storage.");
}
}
/** * Tests writings fails in setMicrotime(). * * @expectedException bandwidthThrottle\tokenBucket\storage\StorageException */ public function testSetMicrotimeFailsWriting() { $this->getFunctionMock(__NAMESPACE__, "fwrite")->expects($this->atLeastOnce())->willReturn(false); vfsStream::setup('test'); $storage = new FileStorage(vfsStream::url("test/data")); $storage->setMicrotime(1.1234); }