Skip to content

Commit

Permalink
Merge pull request #10 from askurihin/fluid_api_fix
Browse files Browse the repository at this point in the history
Fix fluid API for setMaxAttempts
  • Loading branch information
jszobody authored Dec 26, 2020
2 parents 9509275 + 5406ec3 commit 816e461
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Backoff.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ public function __construct(
public function setMaxAttempts($attempts)
{
$this->maxAttempts = $attempts;

return $this;
}

/**
Expand Down
15 changes: 15 additions & 0 deletions tests/BackoffTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 816e461

Please # to comment.