-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a446d12
commit 22fd4f9
Showing
3 changed files
with
56 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Orangesoft\BackOff; | ||
|
||
final class NullBackOff implements BackOffInterface | ||
{ | ||
public function __construct( | ||
private int|float $maxAttempts = 3, | ||
) { | ||
} | ||
|
||
public function backOff(int $attempt, \Throwable $throwable): void | ||
{ | ||
if ($attempt > $this->maxAttempts) { | ||
throw $throwable; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Orangesoft\BackOff\Tests; | ||
|
||
use Orangesoft\BackOff\NullBackOff; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class NullBackOffTest extends TestCase | ||
{ | ||
public function testBackOff(): void | ||
{ | ||
$nullBackOff = new NullBackOff(maxAttempts: 3); | ||
|
||
$throwable = new \Exception(); | ||
|
||
$this->expectExceptionObject($throwable); | ||
|
||
$nullBackOff->backOff(4, $throwable); | ||
} | ||
} |