From 5406ec34b07e8af8d3c13ef2e45a08910434a6de Mon Sep 17 00:00:00 2001 From: Alexandr Skurikhin Date: Sat, 26 Dec 2020 12:03:53 +0300 Subject: [PATCH] Fix fluid API for setMaxAttempts --- src/Backoff.php | 2 ++ tests/BackoffTest.php | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/Backoff.php b/src/Backoff.php index 63cf831..39b874f 100644 --- a/src/Backoff.php +++ b/src/Backoff.php @@ -107,6 +107,8 @@ public function __construct( public function setMaxAttempts($attempts) { $this->maxAttempts = $attempts; + + return $this; } /** diff --git a/tests/BackoffTest.php b/tests/BackoffTest.php index f431333..d1f7efc 100644 --- a/tests/BackoffTest.php +++ b/tests/BackoffTest.php @@ -19,6 +19,21 @@ public function testDefaults() $this->assertFalse($b->jitterEnabled()); } + public function testFluidApi() + { + $b = new Backoff(); + $result = $b + ->setStrategy('constant') + ->setMaxAttempts(10) + ->setWaitCap(5) + ->enableJitter(); + + $this->assertEquals(10, $b->getMaxAttempts()); + $this->assertEquals(5, $b->getWaitCap()); + $this->assertTrue($b->jitterEnabled()); + $this->assertInstanceOf(ConstantStrategy::class, $b->getStrategy()); + } + public function testChangingStaticDefaults() { Backoff::$defaultMaxAttempts = 15;