Skip to content

Commit e35a256

Browse files
bug #62167 [Lock][DynamoDB] Enable http_client injection and fix tests using AmpV5 client (GromNaN)
This PR was squashed before being merged into the 7.4 branch. Discussion ---------- [Lock][DynamoDB] Enable `http_client` injection and fix tests using AmpV5 client | Q | A | ------------- | --- | Branch? | 7.4 | Bug fix? | no | New feature? | yes | Deprecations? | no | Issues | - | License | MIT Replace #62162 to fix the [x86 / minimal-exts / lowest-php](https://github.com/symfony/symfony/actions/runs/18802577388/job/53652067798#logs) job in 8.0 In order to compare instances of `DynamoDbStore`, we need to inject the same `HttpClient` instance. The `http_client` option is a feature that enables, for example, injecting a client decorated by the profiler to view the HTTP requests made by the store, and still use the DSN for the lock configuration. Commits ------- 75289fa [Lock][DynamoDB] Enable `http_client` injection and fix tests using AmpV5 client
2 parents 7bd533c + 75289fa commit e35a256

File tree

2 files changed

+33
-21
lines changed

2 files changed

+33
-21
lines changed

src/Symfony/Component/Lock/Bridge/DynamoDb/Store/DynamoDbStore.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class DynamoDbStore implements PersistingStoreInterface
4747
'write_capacity_units' => 20,
4848
'sslmode' => null,
4949
'debug' => null,
50+
'http_client' => null,
5051
];
5152

5253
private DynamoDbClient $client;
@@ -119,7 +120,7 @@ public function __construct(
119120
$options['table_name'] = $tableName;
120121
}
121122

122-
$this->client = new DynamoDbClient($clientConfiguration);
123+
$this->client = new DynamoDbClient($clientConfiguration, null, $options['http_client']);
123124
}
124125

125126
$this->tableName = $options['table_name'] ?? self::DEFAULT_OPTIONS['table_name'];

src/Symfony/Component/Lock/Bridge/DynamoDb/Tests/Store/DynamoDbStoreTest.php

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,22 @@
1212
namespace Symfony\Component\Lock\Bridge\DynamoDb\Tests\Store;
1313

1414
use AsyncAws\DynamoDb\DynamoDbClient;
15+
use PHPUnit\Framework\Attributes\Before;
1516
use PHPUnit\Framework\TestCase;
17+
use Symfony\Component\HttpClient\MockHttpClient;
1618
use Symfony\Component\Lock\Bridge\DynamoDb\Store\DynamoDbStore;
19+
use Symfony\Contracts\HttpClient\HttpClientInterface;
1720

1821
class DynamoDbStoreTest extends TestCase
1922
{
23+
private HttpClientInterface $httpClient;
24+
25+
#[Before]
26+
public function createMockHttpClient()
27+
{
28+
$this->httpClient = new MockHttpClient([]);
29+
}
30+
2031
public function testExtraOptions()
2132
{
2233
$this->expectException(\InvalidArgumentException::class);
@@ -50,77 +61,77 @@ public function testFromUnsupportedDsn()
5061
public function testFromDsn()
5162
{
5263
$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])
5566
);
5667
}
5768

5869
public function testDsnPrecedence()
5970
{
6071
$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])
6374
);
6475
}
6576

6677
public function testFromDsnWithRegion()
6778
{
6879
$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])
7182
);
7283
}
7384

7485
public function testFromDsnWithCustomEndpoint()
7586
{
7687
$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])
7990
);
8091
}
8192

8293
public function testFromDsnWithSslMode()
8394
{
8495
$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])
8798
);
8899
}
89100

90101
public function testFromDsnWithSslModeOnDefault()
91102
{
92103
$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])
95106
);
96107
}
97108

98109
public function testFromDsnWithCustomEndpointAndPort()
99110
{
100111
$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])
103114
);
104115
}
105116

106117
public function testFromDsnWithQueryOptions()
107118
{
108119
$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])
111122
);
112123
}
113124

114125
public function testFromDsnWithTableNameOption()
115126
{
116127
$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])
119130
);
120131

121132
$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])
124135
);
125136
}
126137

0 commit comments

Comments
 (0)