PHP code example of bshaffer / phpunit-retry-annotations
1. Go to this page and download the library: Download bshaffer/phpunit-retry-annotations library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
bshaffer / phpunit-retry-annotations example snippets
/**
* @retryAttempts 2
*/
class MyTest extends PHPUnit\Framework\TestCase
{
use PHPUnitRetry\RetryTrait;
public function testSomethingFlakeyTwice()
{
// Retry a flakey test up to two times
}
/**
* @retryAttempts 3
*/
public function testSomethingFlakeyThreeTimes()
{
// Retry a flakey test up to three times
}
}
/**
* @retryForSeconds 90
*/
class MyTest extends PHPUnit\Framework\TestCase
{
use PHPUnitRetry\RetryTrait;
public function testSomethingFlakeyFor90Seconds()
{
// retries for 90 seconds
}
/**
* @retryForSeconds 1800
*/
public function testSomethingFlakeyFor30Minutes()
{
// retries for 30 minutes
}
}
/**
* This test will delay with exponential backoff, with a maximum delay of 10 minutes.
*
* @retryAttempts 30
* @retryDelayMethod exponentialBackoff 600
*/
/**
* @retryAttempts 3
* @retryDelayMethod myCustomDelay
*/
public function testWithCustomDelay()
{
// retries using the method `myCustomDelay`.
}
/**
* @param int $attempt The current test attempt
*/
private function myCustomDelay($attempt)
{
// Doubles the sleep each attempt, but not longer than 10 seconds.
sleep(min($attempt * 2, 10));
}
/**
* @retryAttempts 3
* @retryDelayMethod myCustomDelay 10 60
*/
public function testWithCustomDelay()
{
// retries using the method `myCustomDelay`.
}
/**
* @param int $attempt The current test attempt.
* @param int $multiplier Rate of exponential backoff delay.
* @param int $maxDelay Maximum time to wait regardless of retry attempt.
*/
private function myCustomDelay($attempt, $multiplier, $maxDelay)
{
// Increases exponentially
sleep(min($attempt * $multiplier, $max));
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.