$result = $stubborn->resultHandler(function ($stubborn) { if ($stubborn->retries() == 1) { $stubborn->stop(); } $stubborn->retry(); })->retries(2)->run(function () { return 5; }); expect($stubborn->totalTries())->to->be(2); expect($result)->to->be(5); }); it('->staticBackoff()', function ($test) { $stubborn = new Stubborn(); $result = $stubborn->resultHandler(function ($stubborn) { if ($stubborn->retries() < $stubborn->maxRetries()) { $stubborn->staticBackoff(1); } })->retries(2)->run(function () { return 1; }); // kind of arbitrary, can't think of a more accurate way to test // this at this point expect($stubborn->totalBackoffTime())->to->be(2); expect($stubborn->totalTries())->to->be(3); expect($result)->to->be(1); }); it('->exponentialBackoff()', function ($test) { $stubborn = new Stubborn(); $result = $stubborn->resultHandler(function ($stubborn) { if ($stubborn->retries() < $stubborn->maxRetries()) { $stubborn->exponentialBackoff();