PHPUnit Test How Many Times A Function Is Called

Stella_Indiana

New Member
I'm working on a test in phpunit and I'm running into an issue. I have a public function on my class that I am trying to test. Depending on the parameters passed in to the method, a protected function also in my test class will be called one or two times. I currently have a test in place to check that the return data is correct, but I would also like to make sure the protected method is being called the correct number of times.I know that a mock object will allow me to count the number of times a function is called, but it will also override the value returned by the protected function. I tried using a mock object with no "will" section, but it would just return null, not the actual value for the protected method.ExampleClass\[code\]public function do_stuff($runTwice){$results = do_cool_stuff(); if($runTwice){ $results = 2 * do_cool_stuff(); } return $results;}protected function do_cool_stuff(){ return 2;} \[/code\]In my test, I want to check whether do_cool_stuff() was called once or twice, but I still want the return values of both functions to be the same so I can test those as well in my unit test.tl;drI want to count the number of times a protected method in my test object is called (like you can do with a mock object) but I still want all the methods in my test method to return their normal values (not like a mock object).
 
Back
Top