My test suite calls accepted in Object A. That function will then call insert for Object B a certain number of times, depending on which test I’m running.
I want to verify that insert is being called the right amount of times in each test. I don’t think I can count it using mock since Object A wouldn’t be hitting the mock within my test.
I saw this question from 2 years ago:
PHPUnit Test How Many Times A Function Is Called
Using a global variable for counting isn’t ideal since I shouldn’t have code in my class that is specifically for a class.
EDIT
It would probably be helpful to note that insert is static. Even if I mock the class and specify I only want to mock that function, it still calls new on the mocked object which is another roadblock I’m facing.
ANSWER
The answer is no. I just want @zerkms to give that answer since he was the one helping me so I can accept it.
I ended up figuring I can use just one object but did hit another roadblock:
Why isn't PHPUnit counting this function as having ran?
Seems like in this particular case it is impossible.
But in some specific cases you can mock static methods: http://sebastian-bergmann.de/archives/883-Stubbing-and-Mocking-Static-Methods.html
test:
Result: