Let's take in account this scenario
public class FooManager()
{
//somewhere in my manager class code
public function merge(Foo $a, Foo $b, $id)
{
if ($a->getId() == $id) { //!! PAY ATTENTION !!
}
//and so on
}
}
I've read pretty much everywhere that mock an entity isn't a good practice but I'm wondering about that particular piece of code.
If I can't assign an Id to a real entity object (as, for example, it is auto-generated by doctrine), how can I test this functionality without mocking the Foo
entity?
Update
I was thinking about this question and something "flash" in my mind: I'm testing FooManager
here, not Entities. So, to me, use mock is not the only solution but, maybe, even the best. Someone could help me understand if my thinking process is a good one or not?
Update 2
I didn't mentioned it before but, of course, I need to test changes into $a
and $b
($a
will receive some properties values from $b
and will update its properties accordingly). This is the goal of the test as goal of FooManager
is to merge $b
properties into $a
ones (applying some logic, of course)