-
Notifications
You must be signed in to change notification settings - Fork 1
Proposition::given()
$proposition->given(array|Generator ...$generators);
Add the given $generators to the list of generators which will be used to construct arguments during Proposition::call().
For example, if you pass ONE generator into given()
, the $hypothesis
that you pass into call($hypothesis)
should
be a callable which takes a single argument. The value of that argument will be generated by the generator you
passed into $given
. And if given()
is called with TWO generators, the value of $hypothesis
should take TWO
arguments: the value of the first argument is generated by the first generator, the value of the second argument
is generated by the second generator. And so on.
If you want an argument to be e.g. strings half the time and integers the rest of the time, you can do
$proposition->given([Proposition::integers(), Proposition::letterStrings()]);
This is equivalent to using Proposition::combine().
$proposition->given(Proposition::combine(Proposition::integers(), Proposition::letterStrings()));
You can of course call given()
multiple times if you need to. The generators are simply appended one after the
other.
You can provide a custom generator as input, as long as it never returns. Often, it is more convenient to use Proposition::stream() with a callback that returns once.