appwrite/tests/extensions/Retryable.php

38 lines
1,021 B
PHP
Raw Permalink Normal View History

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