forked from igorw/retry
-
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.
Added int type check to $tries and declared strict types (BC break).
Added FailingTooHardException::getAttempts.
- Loading branch information
Showing
5 changed files
with
54 additions
and
17 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 |
---|---|---|
@@ -1,13 +1,29 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace ScriptFUSION\Retry; | ||
|
||
/** | ||
* The exception that is thrown when an operation fails too many times. | ||
*/ | ||
class FailingTooHardException extends \RuntimeException | ||
{ | ||
public function __construct($attempts, \Exception $previous) | ||
private $attempts; | ||
|
||
public function __construct(int $attempts, \Exception $previous) | ||
{ | ||
parent::__construct("Operation failed after $attempts attempt(s).", 0, $previous); | ||
|
||
$this->attempts = $attempts; | ||
} | ||
|
||
/** | ||
* Gets the number of times the operation was attempted before giving up. | ||
* | ||
* @return int Number of attempts. | ||
*/ | ||
public function getAttempts(): int | ||
{ | ||
return $this->attempts; | ||
} | ||
} |
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,18 @@ | ||
<?php | ||
declare(strict_types=1); | ||
|
||
namespace ScriptFUSIONTest\Retry; | ||
|
||
use ScriptFUSION\Retry\FailingTooHardException; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
/** | ||
* @see FailingTooHardException | ||
*/ | ||
final class FailingTooHardExceptionTest extends TestCase | ||
{ | ||
public function testGetAttempts(): void | ||
{ | ||
self::assertSame($attempts = 123, (new FailingTooHardException($attempts, new \Exception()))->getAttempts()); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,12 +1,13 @@ | ||
<phpunit | ||
beStrictAboutOutputDuringTests="true" | ||
> | ||
<testsuite> | ||
<testsuite name="all"> | ||
<directory>.</directory> | ||
</testsuite> | ||
<filter> | ||
<whitelist processUncoveredFilesFromWhitelist="true"> | ||
|
||
<coverage processUncoveredFiles="true"> | ||
<include> | ||
<directory>../src</directory> | ||
</whitelist> | ||
</filter> | ||
</include> | ||
</coverage> | ||
</phpunit> |