mercredi 18 novembre 2015

PHPUnit mocking traits

I've been reading the PHPUnit manual, and there's one part, I just cant see the point of, to do with mocking traits.

http://ift.tt/15yLTJz (figure 9.18)

In their example, there's the concrete method which returns the value from an abstract method (which is ultimately mocked by the test).

Unfortunately the 2 sentence explanation doesn't explain why this is useful! As far as I can see, the test will obviously pass, but in the real world, the abstract method wouldn't be mocked and it would actually fail?

Are we meant to remove the abstract method and replace the call to it in the concrete method? If so, what's the point in the test? Why are we cluttering the traits with abstract methods that aren't actually used?

My ultimate question is, why is the test written to pass in testing when if used in the real world, it would fail? If someone could help me understand it, it'd be grateful!

Aucun commentaire:

Enregistrer un commentaire