I have a unit test that asserts whether a particular model has a property or not and whether that property is not null.
So, something like the following:
public function testHasMySpecialProperty()
{
$this->assertTrue($this->model->getMySpecialProperty());
}
my question is what should model be. A mock, or a real instatition of the object.
The object in this case is a user of a system. So in order to load properly i would require the user id etc. But if i simply fake it then the test feels useless
It depends. Use mocks to stub out behavior of complex objects or objects with external dependencies, when that object is not the subject of the test.
So, if you are testing the behavior of
model, use the real thing. Ifmodelis a data object, with no behavior and no attachment to external resources (ex, does not make database calls), then use the real thing. Ifmodelhas some additional behavior or dependencies, and it is not the target of the test, go ahead and mock it.