/**
* Precondition: $values should fail $this->assertion
*/
public function from(array $elements, AssertionFailed $exception)
{
$onBadShrink = function () use(&$exception) {
$this->attempts->increase();
$this->attempts->ensureLimit($exception);
};
$onGoodShrink = function ($elementsAfterShrink, $exceptionAfterShrink) use(&$elements, &$exception) {
$this->attempts->reset();
$elements = $elementsAfterShrink;
$exception = $exceptionAfterShrink;
};
$this->timeLimit->start();
while (!$this->timeLimit->hasBeenReached()) {
$elementsAfterShrink = $this->generator->shrink($elements);
if ($elementsAfterShrink === $elements) {
$onBadShrink();
continue;
}
if (!$this->checkGoodShrinkConditions($elementsAfterShrink)) {
$onBadShrink();
continue;
}
Evaluation::of($this->assertion)->with($elementsAfterShrink)->onFailure($onGoodShrink)->onSuccess($onBadShrink)->execute();
}
throw new \RuntimeException("Eris has reached the time limit for shrinking, here it is presenting the simplest failure case." . PHP_EOL . "If you can afford to spend more time to find a simpler failing input, increase \$this->shrinkingTimeLimit or set it to null to remove it.", -1, $exception);
}