-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathAwsRetryStrategyTest.php
More file actions
47 lines (40 loc) · 1.55 KB
/
AwsRetryStrategyTest.php
File metadata and controls
47 lines (40 loc) · 1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
namespace AsyncAws\Core\Tests\HttpClient;
use AsyncAws\Core\HttpClient\AwsRetryStrategy;
use AsyncAws\Core\Test\TestCase;
use PHPUnit\Framework\Attributes\DataProvider;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\HttpClient\Response\AsyncContext;
use Symfony\Component\HttpClient\Response\MockResponse;
use Symfony\Component\HttpClient\Retry\GenericRetryStrategy;
class AwsRetryStrategyTest extends TestCase
{
#[DataProvider('provideRetries')]
public function testShouldRetry(?bool $expected, int $statusCode, ?string $response): void
{
if (!class_exists(GenericRetryStrategy::class)) {
self::markTestSkipped('AwsRetryStrategy requires symfony/http-client 5.2');
}
$strategy = new AwsRetryStrategy();
$context = $this->getContext($statusCode);
self::assertSame($expected, $strategy->shouldRetry($context, $response, null));
}
public static function provideRetries(): iterable
{
yield [false, 200, null];
yield [true, 429, null];
yield [null, 400, null];
yield [false, 400, 'this is invalid'];
yield [false, 400, '{"__type": "RandomError"}'];
yield [true, 400, '{"__type": "RequestLimitExceeded"}'];
}
private function getContext(int $statusCode): AsyncContext
{
$passthru = null;
$info = [
'http_code' => $statusCode,
];
$response = new MockResponse('', $info);
return new AsyncContext($passthru, new MockHttpClient(), $response, $info, null, 0);
}
}