So I've decided to investigate using seams in PHPUnit, but I came across a problem
I rearranged my class in a way that I broke the dependencies to database class
db_Class::getMyData($vars);
became
self::getMyData($vars);
and I added functions to my code
protected static function getMyData($vars) {
return db_Class::getMyData($vars);
}
This was done so I can make a class that inherits this class and overloads the getMyData function. To be able to alter it when I run my test cases.
So for example in the seam class that extends the class above and overloads that function:
protected static function getMyData($vars) {
return array('id'=>1, 'name'=>"My Name");
}
This would be very useful, as I can alter the data as I like. However when using PHPUnit you have the possibility to run mocks using $this->getMock and similar. Would I ever be able to achieve this inside the seam class.
I'm trying to look for a solution where I am not using a dependency injector, which would be my other alternative, not so bad at all, just want to evaluate both alternatives.
Michael C. Feathers expressed a seam to be the following:
A seam is a place where you can alter behavior in your program without editing in that place.
So I might not get the full picture, and I've been trying to get it for a while now, and I just cant get my head around it. Please comment if you have any ideas or questions.
What I ask for is a way to work with mocks easy in different scenarios. I dont always want to return the same value in the seam, sometimes I want to return null to get an error, and sometimes an array with correct data, and sometimes something else probably.
Thanks