I'm playing around with PHPUnit. I've managed to get a test to run, but I'm having some trouble testing a specific method.
I have static method \Model\Category::corporate(\Model\Client $client) which obviously takes a \Model\Client object as a parameter (is this an implicit or explicit dependency?) I want to make sure that \Model\Category::corporate() returns an array. This is my TestCase:
I looked through the call stack and found that the root source of the error is the call to "getMock('\\Model\\Client')". It also appears that the error is being thrown within the ORM package, when attempting to loop over internal properties. Beyond that, I'm clueless.
From what I understand, manually creating a \Model\Client object to pass to the method I am testing is a bad way of doing things. Is that correct?
I'm *supposed* to be making implicit dependencies explicit by using dependency injection (I think).
Should I explicitly create a \Model\Client object to pass to the method I'm testing? Or how else would I go about testing my \Model\Category::corporate() method?
You've hit one of the reasons for redesigning the Fuel architecture for v2. The current architecture doesn't lend itself to being tested.
I don't know what your \Model\Category::corporate() does, but it clearly expects a fully functional ORM model, and not a mockup. getMock() is meant to create pseudo objects that have dummy methods on which you can define behaviour so you can test them.
An ORM object is a complex object, has lots of static methods and data, and also constructs new objects internally. All a big no-no if you want proper testing.