Reputation: 35796
In phpspec can i mock the return value of a method?
for example:
class MyClass()
{
public function getStaffMemberNames()
{
// db call to get array of staff member names
}
public function sortStaffMemberNames()
{
return sort($this->getStaffMemberNames());
}
}
I am interested in testing the sortStaffMemberNames method. But it relies on another class method which uses a db connection. I want to mock the getStaffMemberNames so i can easily test.
How can this be achieved?
Upvotes: 3
Views: 1015
Reputation: 36241
There's no partial mocks in phpspec (you cannot mock the class under test). This is a bad practice.
You should mock your collaborators instead (database connection for example).
Upvotes: 3