Skip to content

Commit 4f43ee8

Browse files
authored
chore: Add test covering direct DynamoDbClient injection (#22)
1 parent ccb1380 commit 4f43ee8

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

tests/DynamoDbFeatureRequesterTest.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,14 @@ protected function makeRequester($prefix)
5050
}
5151

5252
protected function putSerializedItem($prefix, $namespace, $key, $version, $json): void
53+
{
54+
$this->putSerializedItemWithClient(self::$dynamoDbClient, $prefix, $namespace, $key, $version, $json);
55+
}
56+
57+
protected function putSerializedItemWithClient($client, $prefix, $namespace, $key, $version, $json): void
5358
{
5459
$prefixedNamespace = self::realPrefix($prefix) . $namespace;
55-
self::$dynamoDbClient->putItem(array(
60+
$client->putItem(array(
5661
'TableName' => self::TABLE_NAME,
5762
'Item' => array(
5863
'namespace' => array('S' => $prefixedNamespace),
@@ -137,4 +142,18 @@ private static function createTableIfNecessary()
137142
sleep(1);
138143
}
139144
}
145+
146+
public function testCanProvideFullyConfiguredClient()
147+
{
148+
$flagJson = '{"key": "flag-key", "version": 1, "on": true, "prerequisites": [], "salt": "key", "targets": [], "rules": [], "fallthrough": { "variation": 0 }, "offVariation": 0, "variations": [true, false], "deleted": false}';
149+
150+
$client = new DynamoDbClient(self::makeDynamoDbOptions());
151+
$this->putSerializedItemWithClient($client, 'my-prefix', 'features', 'flag-key', 1, $flagJson);
152+
153+
$requesterFn = DynamoDb::featureRequester(['dynamodb_client' => $client, 'dynamodb_table' => self::TABLE_NAME, 'dynamodb_prefix' => 'my-prefix']);
154+
$requester = $requesterFn('', '', []);
155+
$flag = $requester->getFeature("flag-key");
156+
157+
$this->assertEquals('flag-key', $flag->getKey());
158+
}
140159
}

0 commit comments

Comments
 (0)