Files
appwrite/tests/extensions/Retryable.php
T
Jake Barnby 46f3fadc5d Fix hooks
2026-01-15 17:21:05 +13:00

38 lines
1021 B
PHP

<?php
namespace Appwrite\Tests;
/**
* Marker trait for classes that support retry functionality.
* The actual retry logic is handled by the RetrySubscriber extension.
*
* Test methods can be annotated with #[Retry(count: N)] to enable retries.
* When a test with this attribute fails, the RetrySubscriber logs the failure
* and tracks retry attempts.
*/
trait Retryable
{
/**
* Get the number of retries configured for the current test method.
*
* @return int
* @throws \ReflectionException
*/
public function getNumberOfRetries(): int
{
$root = new \ReflectionClass($this);
$name = $this->name();
if (!$root->hasMethod($name)) {
return 0;
}
$method = $root->getMethod($name);
$attributes = $method->getAttributes(Retry::class);
$attribute = $attributes[0] ?? null;
$args = $attribute?->getArguments();
$retries = $args['count'] ?? $args[0] ?? 0;
return \max(0, $retries);
}
}