I’m using PHPUnit and my traditional approach is to use mock objects and methods that get called by the methods I’m testing. The mock objects are told what to expect as input by the unit test. The problem is that part of the input supplied to the mock objects are being randomly generated by the methods being tested (and the unit test has no way of knowing what those are).
Just wondering if anyone could suggest a solution.
Can the “random part” be injected into the method (or is the randomness the core feature)?
E.g. (maybe a oversimplified example taking “random” literally) instead of
use something like
This way you eliminate as much “randomness” as possible in your tests, since you can pass an object for $r that doesn’t really return random values but e.g. edge cases.