1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GuillermoandraeTest\DynamoDb\Operation; |
4
|
|
|
|
5
|
|
|
use Guillermoandrae\DynamoDb\Constant\AttributeTypes; |
6
|
|
|
use Guillermoandrae\DynamoDb\Constant\BillingModes; |
7
|
|
|
use Guillermoandrae\DynamoDb\Constant\KeyTypes; |
8
|
|
|
use Guillermoandrae\DynamoDb\Constant\ProjectionTypes; |
9
|
|
|
use Guillermoandrae\DynamoDb\Constant\StreamViewTypes; |
10
|
|
|
use Guillermoandrae\DynamoDb\Factory\DynamoDbClientFactory; |
11
|
|
|
use Guillermoandrae\DynamoDb\Factory\MarshalerFactory; |
12
|
|
|
use Guillermoandrae\DynamoDb\Operation\CreateTableOperation; |
13
|
|
|
use GuillermoandraeTest\DynamoDb\TestCase; |
14
|
|
|
|
15
|
|
|
final class CreateTableOperationTest extends TestCase |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var string The table name; |
19
|
|
|
*/ |
20
|
|
|
private $tableName = 'test'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var array The primary key. |
24
|
|
|
*/ |
25
|
|
|
private $keySchema = ['name' => [AttributeTypes::STRING, KeyTypes::HASH]]; |
26
|
|
|
|
27
|
|
|
public function testSetPartitionKey() |
28
|
|
|
{ |
29
|
|
|
$operation = new CreateTableOperation( |
30
|
|
|
DynamoDbClientFactory::factory(), |
31
|
|
|
MarshalerFactory::factory(), |
32
|
|
|
$this->tableName |
33
|
|
|
); |
34
|
|
|
$operation->setPartitionKey('test', AttributeTypes::STRING); |
35
|
|
|
$this->assertEquals(KeyTypes::HASH, $operation->toArray()['KeySchema'][0]['KeyType']); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
public function testSetSortKey() |
39
|
|
|
{ |
40
|
|
|
$operation = new CreateTableOperation( |
41
|
|
|
DynamoDbClientFactory::factory(), |
42
|
|
|
MarshalerFactory::factory(), |
43
|
|
|
$this->tableName |
44
|
|
|
); |
45
|
|
|
$operation->setSortKey('test', AttributeTypes::STRING); |
46
|
|
|
$this->assertEquals(KeyTypes::RANGE, $operation->toArray()['KeySchema'][0]['KeyType']); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
public function testSetReadCapacityUnits() |
50
|
|
|
{ |
51
|
|
|
$operation = new CreateTableOperation( |
52
|
|
|
DynamoDbClientFactory::factory(), |
53
|
|
|
MarshalerFactory::factory(), |
54
|
|
|
$this->tableName |
55
|
|
|
); |
56
|
|
|
$operation->setReadCapacityUnits(10); |
57
|
|
|
$this->assertEquals(10, $operation->toArray()['ProvisionedThroughput']['ReadCapacityUnits']); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testWriteCapacityUnits() |
61
|
|
|
{ |
62
|
|
|
$operation = new CreateTableOperation( |
63
|
|
|
DynamoDbClientFactory::factory(), |
64
|
|
|
MarshalerFactory::factory(), |
65
|
|
|
$this->tableName |
66
|
|
|
); |
67
|
|
|
$operation->setWriteCapacityUnits(20); |
68
|
|
|
$this->assertEquals(20, $operation->toArray()['ProvisionedThroughput']['WriteCapacityUnits']); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testSetBillingMode() |
72
|
|
|
{ |
73
|
|
|
$operation = new CreateTableOperation( |
74
|
|
|
DynamoDbClientFactory::factory(), |
75
|
|
|
MarshalerFactory::factory(), |
76
|
|
|
$this->tableName |
77
|
|
|
); |
78
|
|
|
$operation->setBillingMode(BillingModes::PAY_PER_REQUEST); |
79
|
|
|
$this->assertEquals(BillingModes::PAY_PER_REQUEST, $operation->toArray()['BillingMode']); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testSSESpecification() |
83
|
|
|
{ |
84
|
|
|
$operation = new CreateTableOperation( |
85
|
|
|
DynamoDbClientFactory::factory(), |
86
|
|
|
MarshalerFactory::factory(), |
87
|
|
|
$this->tableName |
88
|
|
|
); |
89
|
|
|
$operation->setSSESpecification(true, 'someKey'); |
90
|
|
|
$this->assertEquals('someKey', $operation->toArray()['SSESpecification']['KMSMasterKeyId']); |
91
|
|
|
$operation->setSSESpecification(false); |
92
|
|
|
$this->assertArrayNotHasKey('SSESpecification', $operation->toArray()); |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function testAddGlobalSecondaryIndex() |
96
|
|
|
{ |
97
|
|
|
$operation = new CreateTableOperation( |
98
|
|
|
DynamoDbClientFactory::factory(), |
99
|
|
|
MarshalerFactory::factory(), |
100
|
|
|
$this->tableName |
101
|
|
|
); |
102
|
|
|
$expectedIndexName = 'test'; |
103
|
|
|
$expectedKeySchema = [['class', KeyTypes::HASH]]; |
104
|
|
|
$expectedProjection = ['thing', ProjectionTypes::INCLUDE]; |
105
|
|
|
$operation->addGlobalSecondaryIndex($expectedIndexName, $expectedKeySchema, $expectedProjection); |
106
|
|
|
$request = $operation->toArray()['GlobalSecondaryIndexes'][0]; |
107
|
|
|
$this->assertEquals($expectedIndexName, $request['IndexName']); |
108
|
|
|
$this->assertEquals($expectedKeySchema[0][0], $request['KeySchema'][0]['AttributeName']); |
109
|
|
|
$this->assertEquals($expectedKeySchema[0][1], $request['KeySchema'][0]['KeyType']); |
110
|
|
|
$this->assertEquals($expectedProjection[0], $request['Projection']['NonKeyAttributes']); |
111
|
|
|
$this->assertEquals($expectedProjection[1], $request['Projection']['ProjectionType']); |
112
|
|
|
} |
113
|
|
|
|
114
|
|
|
public function testSetGlobalSecondaryIndexWithProvisionedThroughput() |
115
|
|
|
{ |
116
|
|
|
$operation = new CreateTableOperation( |
117
|
|
|
DynamoDbClientFactory::factory(), |
118
|
|
|
MarshalerFactory::factory(), |
119
|
|
|
$this->tableName |
120
|
|
|
); |
121
|
|
|
$expectedIndexName = 'test'; |
122
|
|
|
$expectedKeySchema = [['class', KeyTypes::HASH]]; |
123
|
|
|
$expectedProjection = ['thing', ProjectionTypes::INCLUDE]; |
124
|
|
|
$expectedProvisionedThroughput = [5, 5]; |
125
|
|
|
$operation->addGlobalSecondaryIndex( |
126
|
|
|
$expectedIndexName, |
127
|
|
|
$expectedKeySchema, |
128
|
|
|
$expectedProjection, |
129
|
|
|
$expectedProvisionedThroughput |
130
|
|
|
); |
131
|
|
|
$this->assertEquals( |
132
|
|
|
$expectedProvisionedThroughput[0], |
133
|
|
|
$operation->toArray()['GlobalSecondaryIndexes'][0]['ProvisionedThroughput']['ReadCapacityUnits'] |
134
|
|
|
); |
135
|
|
|
$this->assertEquals( |
136
|
|
|
$expectedProvisionedThroughput[1], |
137
|
|
|
$operation->toArray()['GlobalSecondaryIndexes'][0]['ProvisionedThroughput']['WriteCapacityUnits'] |
138
|
|
|
); |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function testAddLocalSecondaryIndex() |
142
|
|
|
{ |
143
|
|
|
$operation = new CreateTableOperation( |
144
|
|
|
DynamoDbClientFactory::factory(), |
145
|
|
|
MarshalerFactory::factory(), |
146
|
|
|
$this->tableName |
147
|
|
|
); |
148
|
|
|
$expectedIndexName = 'test'; |
149
|
|
|
$expectedKeySchema = [['class', KeyTypes::HASH]]; |
150
|
|
|
$expectedProjection = ['thing', ProjectionTypes::INCLUDE]; |
151
|
|
|
$operation->addLocalSecondaryIndex($expectedIndexName, $expectedKeySchema, $expectedProjection); |
152
|
|
|
$request = $operation->toArray()['LocalSecondaryIndexes'][0]; |
153
|
|
|
$this->assertEquals($expectedIndexName, $request['IndexName']); |
154
|
|
|
$this->assertEquals($expectedKeySchema[0][0], $request['KeySchema'][0]['AttributeName']); |
155
|
|
|
$this->assertEquals($expectedKeySchema[0][1], $request['KeySchema'][0]['KeyType']); |
156
|
|
|
$this->assertEquals($expectedProjection[0], $request['Projection']['NonKeyAttributes']); |
157
|
|
|
$this->assertEquals($expectedProjection[1], $request['Projection']['ProjectionType']); |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
public function testSetStreamSpecification() |
161
|
|
|
{ |
162
|
|
|
$operation = new CreateTableOperation( |
163
|
|
|
DynamoDbClientFactory::factory(), |
164
|
|
|
MarshalerFactory::factory(), |
165
|
|
|
$this->tableName |
166
|
|
|
); |
167
|
|
|
$expectedStreamEnabled = true; |
168
|
|
|
$expectedStreamViewType = StreamViewTypes::KEYS_ONLY; |
169
|
|
|
$operation->setStreamSpecification($expectedStreamEnabled, $expectedStreamViewType); |
170
|
|
|
$request = $operation->toArray()['StreamSpecification']; |
171
|
|
|
$this->assertEquals($expectedStreamEnabled, $request['StreamEnabled']); |
172
|
|
|
$this->assertEquals($expectedStreamViewType, $request['StreamViewType']); |
173
|
|
|
$operation->setStreamSpecification(false); |
174
|
|
|
$this->assertArrayNotHasKey('StreamViewType', $operation->toArray()['StreamSpecification']); |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
public function testAddTag() |
178
|
|
|
{ |
179
|
|
|
$operation = new CreateTableOperation( |
180
|
|
|
DynamoDbClientFactory::factory(), |
181
|
|
|
MarshalerFactory::factory(), |
182
|
|
|
$this->tableName, |
183
|
|
|
$this->keySchema |
184
|
|
|
); |
185
|
|
|
$operation->addTag('someKey', 'someValue'); |
186
|
|
|
$operation->addTag('anotherKey', 'anotherValue'); |
187
|
|
|
$this->assertEquals('someValue', $operation->toArray()['Tags'][0]['Value']); |
188
|
|
|
$this->assertEquals('anotherValue', $operation->toArray()['Tags'][1]['Value']); |
189
|
|
|
} |
190
|
|
|
} |
191
|
|
|
|