|
12 | 12 | namespace Symfony\Component\Lock\Bridge\DynamoDb\Tests\Store; |
13 | 13 |
|
14 | 14 | use AsyncAws\DynamoDb\DynamoDbClient; |
| 15 | +use PHPUnit\Framework\Attributes\Before; |
15 | 16 | use PHPUnit\Framework\TestCase; |
| 17 | +use Symfony\Component\HttpClient\MockHttpClient; |
16 | 18 | use Symfony\Component\Lock\Bridge\DynamoDb\Store\DynamoDbStore; |
| 19 | +use Symfony\Contracts\HttpClient\HttpClientInterface; |
17 | 20 |
|
18 | 21 | class DynamoDbStoreTest extends TestCase |
19 | 22 | { |
| 23 | + private HttpClientInterface $httpClient; |
| 24 | + |
| 25 | + #[Before] |
| 26 | + public function createMockHttpClient() |
| 27 | + { |
| 28 | + $this->httpClient = new MockHttpClient([]); |
| 29 | + } |
| 30 | + |
20 | 31 | public function testExtraOptions() |
21 | 32 | { |
22 | 33 | $this->expectException(\InvalidArgumentException::class); |
@@ -50,77 +61,77 @@ public function testFromUnsupportedDsn() |
50 | 61 | public function testFromDsn() |
51 | 62 | { |
52 | 63 | $this->assertEquals( |
53 | | - new DynamoDbStore(new DynamoDbClient(['region' => null, 'accessKeyId' => null, 'accessKeySecret' => null]), ['table_name' => 'table']), |
54 | | - new DynamoDbStore('dynamodb://default/table', []) |
| 64 | + new DynamoDbStore(new DynamoDbClient(['region' => null, 'accessKeyId' => null, 'accessKeySecret' => null], null, $this->httpClient), ['table_name' => 'table']), |
| 65 | + new DynamoDbStore('dynamodb://default/table', ['http_client' => $this->httpClient]) |
55 | 66 | ); |
56 | 67 | } |
57 | 68 |
|
58 | 69 | public function testDsnPrecedence() |
59 | 70 | { |
60 | 71 | $this->assertEquals( |
61 | | - new DynamoDbStore(new DynamoDbClient(['region' => 'us-east-2', 'accessKeyId' => 'key_dsn', 'accessKeySecret' => 'secret_dsn']), ['table_name' => 'table_dsn']), |
62 | | - new DynamoDbStore('dynamodb://key_dsn:secret_dsn@default/table_dsn?region=us-east-2', ['region' => 'eu-west-3', 'table_name' => 'table_options']) |
| 72 | + new DynamoDbStore(new DynamoDbClient(['region' => 'us-east-2', 'accessKeyId' => 'key_dsn', 'accessKeySecret' => 'secret_dsn'], null, $this->httpClient), ['table_name' => 'table_dsn']), |
| 73 | + new DynamoDbStore('dynamodb://key_dsn:secret_dsn@default/table_dsn?region=us-east-2', ['region' => 'eu-west-3', 'table_name' => 'table_options', 'http_client' => $this->httpClient]) |
63 | 74 | ); |
64 | 75 | } |
65 | 76 |
|
66 | 77 | public function testFromDsnWithRegion() |
67 | 78 | { |
68 | 79 | $this->assertEquals( |
69 | | - new DynamoDbStore(new DynamoDbClient(['region' => 'us-west-2', 'accessKeyId' => null, 'accessKeySecret' => null]), ['table_name' => 'table']), |
70 | | - new DynamoDbStore('dynamodb://default/table?region=us-west-2', []) |
| 80 | + new DynamoDbStore(new DynamoDbClient(['region' => 'us-west-2', 'accessKeyId' => null, 'accessKeySecret' => null], null, $this->httpClient), ['table_name' => 'table']), |
| 81 | + new DynamoDbStore('dynamodb://default/table?region=us-west-2', ['http_client' => $this->httpClient]) |
71 | 82 | ); |
72 | 83 | } |
73 | 84 |
|
74 | 85 | public function testFromDsnWithCustomEndpoint() |
75 | 86 | { |
76 | 87 | $this->assertEquals( |
77 | | - new DynamoDbStore(new DynamoDbClient(['region' => null, 'endpoint' => 'https://localhost', 'accessKeyId' => null, 'accessKeySecret' => null]), ['table_name' => 'table']), |
78 | | - new DynamoDbStore('dynamodb://localhost/table', []) |
| 88 | + new DynamoDbStore(new DynamoDbClient(['region' => null, 'endpoint' => 'https://localhost', 'accessKeyId' => null, 'accessKeySecret' => null], null, $this->httpClient), ['table_name' => 'table']), |
| 89 | + new DynamoDbStore('dynamodb://localhost/table', ['http_client' => $this->httpClient]) |
79 | 90 | ); |
80 | 91 | } |
81 | 92 |
|
82 | 93 | public function testFromDsnWithSslMode() |
83 | 94 | { |
84 | 95 | $this->assertEquals( |
85 | | - new DynamoDbStore(new DynamoDbClient(['region' => null, 'endpoint' => 'http://localhost', 'accessKeyId' => null, 'accessKeySecret' => null]), ['table_name' => 'table']), |
86 | | - new DynamoDbStore('dynamodb://localhost/table?sslmode=disable', []) |
| 96 | + new DynamoDbStore(new DynamoDbClient(['region' => null, 'endpoint' => 'http://localhost', 'accessKeyId' => null, 'accessKeySecret' => null], null, $this->httpClient), ['table_name' => 'table']), |
| 97 | + new DynamoDbStore('dynamodb://localhost/table?sslmode=disable', ['http_client' => $this->httpClient]) |
87 | 98 | ); |
88 | 99 | } |
89 | 100 |
|
90 | 101 | public function testFromDsnWithSslModeOnDefault() |
91 | 102 | { |
92 | 103 | $this->assertEquals( |
93 | | - new DynamoDbStore(new DynamoDbClient(['region' => null, 'accessKeyId' => null, 'accessKeySecret' => null]), ['table_name' => 'table']), |
94 | | - new DynamoDbStore('dynamodb://default/table?sslmode=disable', []) |
| 104 | + new DynamoDbStore(new DynamoDbClient(['region' => null, 'accessKeyId' => null, 'accessKeySecret' => null], null, $this->httpClient), ['table_name' => 'table']), |
| 105 | + new DynamoDbStore('dynamodb://default/table?sslmode=disable', ['http_client' => $this->httpClient]) |
95 | 106 | ); |
96 | 107 | } |
97 | 108 |
|
98 | 109 | public function testFromDsnWithCustomEndpointAndPort() |
99 | 110 | { |
100 | 111 | $this->assertEquals( |
101 | | - new DynamoDbStore(new DynamoDbClient(['region' => null, 'endpoint' => 'https://localhost:1234', 'accessKeyId' => null, 'accessKeySecret' => null]), ['table_name' => 'table']), |
102 | | - new DynamoDbStore('dynamodb://localhost:1234/table', []) |
| 112 | + new DynamoDbStore(new DynamoDbClient(['region' => null, 'endpoint' => 'https://localhost:1234', 'accessKeyId' => null, 'accessKeySecret' => null], null, $this->httpClient), ['table_name' => 'table']), |
| 113 | + new DynamoDbStore('dynamodb://localhost:1234/table', ['http_client' => $this->httpClient]) |
103 | 114 | ); |
104 | 115 | } |
105 | 116 |
|
106 | 117 | public function testFromDsnWithQueryOptions() |
107 | 118 | { |
108 | 119 | $this->assertEquals( |
109 | | - new DynamoDbStore(new DynamoDbClient(['region' => null, 'accessKeyId' => null, 'accessKeySecret' => null]), ['table_name' => 'table', 'id_attr' => 'id_dsn']), |
110 | | - new DynamoDbStore('dynamodb://default/table?id_attr=id_dsn', []) |
| 120 | + new DynamoDbStore(new DynamoDbClient(['region' => null, 'accessKeyId' => null, 'accessKeySecret' => null], null, $this->httpClient), ['table_name' => 'table', 'id_attr' => 'id_dsn']), |
| 121 | + new DynamoDbStore('dynamodb://default/table?id_attr=id_dsn', ['http_client' => $this->httpClient]) |
111 | 122 | ); |
112 | 123 | } |
113 | 124 |
|
114 | 125 | public function testFromDsnWithTableNameOption() |
115 | 126 | { |
116 | 127 | $this->assertEquals( |
117 | | - new DynamoDbStore(new DynamoDbClient(['region' => null, 'accessKeyId' => null, 'accessKeySecret' => null]), ['table_name' => 'table']), |
118 | | - new DynamoDbStore('dynamodb://default', ['table_name' => 'table']) |
| 128 | + new DynamoDbStore(new DynamoDbClient(['region' => null, 'accessKeyId' => null, 'accessKeySecret' => null], null, $this->httpClient), ['table_name' => 'table']), |
| 129 | + new DynamoDbStore('dynamodb://default', ['table_name' => 'table', 'http_client' => $this->httpClient]) |
119 | 130 | ); |
120 | 131 |
|
121 | 132 | $this->assertEquals( |
122 | | - new DynamoDbStore(new DynamoDbClient(['region' => null, 'accessKeyId' => null, 'accessKeySecret' => null]), ['table_name' => 'table']), |
123 | | - new DynamoDbStore('dynamodb://default/table', ['table_name' => 'table_ignored']) |
| 133 | + new DynamoDbStore(new DynamoDbClient(['region' => null, 'accessKeyId' => null, 'accessKeySecret' => null], null, $this->httpClient), ['table_name' => 'table']), |
| 134 | + new DynamoDbStore('dynamodb://default/table', ['table_name' => 'table_ignored', 'http_client' => $this->httpClient]) |
124 | 135 | ); |
125 | 136 | } |
126 | 137 |
|
|
0 commit comments