I have a created a minor wrapper function for the php time()
method in my class
class MyClass
{
public function myFuncion($unixTimeStamp)
{
$pending = $this->isPending($unixTimeStamp)
// data manipulation
return $result
}
protected function isPending($unixTimeStamp)
{
if ($unixTimeStamp > $this->currentTime()) {
return true;
}
return false;
}
public function currentTime()
{
return time();
}
}
I want to test the public function myFunction()
in this class but I am at a bit of a loss how I can mock the currentTime method without mocking the SUT itself (MyClass)
What is the correct way of doing this? I felt creating a time class with a single method (getCurrentTime) and injecting it into MyClass
while correct, was excessive as I only check the time in one place in my code.
Is this the best method regardless?
EDIT: I am considering making a time
trait as it looks like PhpUnit can mock this. Still unsure if this is overkill for use in a single method..
What other options do I have?