Assume there is a method
public function updateTimestamp($sessionId, $data)
{
return $this->memcached->touch($sessionId, time() + $this->ttl);
}
that I'd like to test. Infection changes the + in time() + $this->ttl to - and all my tests are still passing. So I'd like to make a test that will mock Memcached's touch in it and will conditionally return true/false basing on the second argument passed to it.
So doing something like:
// $ttl is set;
$memcachedMock
->touch(
'sessionId',
$certainValuePassedToTouch
)
->willReturn(
$certainValuePassedToTouch >= time() + $ttl
? true
: false
)
;
There are two problems now:
- I don't know how to make such a condition for an arbitrary integer parameter passed to the method being mocked
- basing on time() seems to be very unreliable, so how can I reliably test it if time() is used in the method itself?