How to mock with static methods?

Yes, you use instance methods. Static methods basically say, “There is one way to accomplish this functionality – it’s not polymorphic.” Mocking relies on polymorphism.

Now, if your static methods logically don’t care about what implementation you’re using, they might be able to take the interfaces as parameters, or perhaps work without interacting with state at all – but otherwise you should be using instances (and probably dependency injection to wire everything together).

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)