Beispiel #1
0
     $stubborn = new Stubborn();
     $result = $stubborn->retries(1)->resultHandler(function ($stubborn) {
         $stubborn->delayRetry();
     })->run(function () {
         return 'Kaboom';
     });
     expect($stubborn->totalBackoffTime())->to->be->within(1, 2);
     expect($stubborn->totalTries())->to->be(2);
     expect($result)->to->be('Kaboom');
 });
 it('->reset()', function ($test) {
     $total_tries = 0;
     $stubborn = new Stubborn();
     $result = $stubborn->retries(3)->resultHandler(function ($stubborn) use(&$total_tries) {
         if ($stubborn->retries() == 2 && $stubborn->retries() == $total_tries) {
             $stubborn->reset();
         }
         $total_tries++;
         $stubborn->retry();
     })->run(function () {
         return 3;
     });
     expect($total_tries)->to->be(6);
     expect($stubborn->totalTries())->to->be(4);
     expect($result)->to->be(3);
 });
 it('->resetAndRun()', function ($test) {
     $total_tries = 0;
     $stubborn = new Stubborn();
     $result = $stubborn->retries(3)->resultHandler(function ($stubborn) use(&$total_tries) {
         if ($stubborn->retries() == 2 && $stubborn->retries() == $total_tries) {