I am refactoring a class while writing unit tests for it. There is a case that one of my methods is completely calling another object's methods which is injected to this class that I am testing.
So I have to mock the object that I have injected to class.
Now, the questing is that, does it worth to write unit tests for this particular method? It seems to be strange to write unit tests which all it does it calling other object's methods which that object itself has to be mocked, then why am I testing this method at all?
Isn't the purpose of testing to check functionality of a method whether it works as expected or not? If it is, then when I am mocking all it has and there is nothing left of that particular method to test then why should I test?
I am really confused!
The method which I'm stuck at is this (which is used for custom session handling):
public function write($sessionId, $sessionData)
{
$sth = $this->databaseConnection->prepare("INSERT INTO `{$this->DBTableName}` (`session_id`,`session_name`,`session_data`) VALUES(:session_id, :session_name, :session_data) ON DUPLICATE KEY UPDATE `session_data`=:session_data;");
$sth->bindValue(':session_id', $sessionId);
$sth->bindValue(':session_name', $this->sessionName);
$sth->bindValue(':session_data', $sessionData);
return $sth->execute();
}
here is link for this piece of code as well: http://pastebin.com/1FBeU6mb
By the way, I am newly started writing tests for my classes and I am beginner in this field of testing and inexperienced.
Thanks in advance.