1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GuillermoandraeTest\Db\DynamoDb; |
4
|
|
|
|
5
|
|
|
use Aws\DynamoDb\Marshaler; |
6
|
|
|
use Guillermoandrae\Db\DynamoDb\AttributeTypes; |
7
|
|
|
use Guillermoandrae\Db\DynamoDb\CreateTableRequest; |
8
|
|
|
use Guillermoandrae\Db\DynamoDb\KeyTypes; |
9
|
|
|
use PHPUnit\Framework\TestCase; |
10
|
|
|
|
11
|
|
|
final class CreateTableRequestTest extends TestCase |
12
|
|
|
{ |
13
|
|
|
private $data = ['name' => ['type' => AttributeTypes::STRING, 'keyType' => KeyTypes::HASH]]; |
14
|
|
|
|
15
|
|
|
public function testSetPartitionKey() |
16
|
|
|
{ |
17
|
|
|
$request = new CreateTableRequest(new Marshaler(), 'test'); |
18
|
|
|
$request->setPartitionKey('test', AttributeTypes::STRING); |
19
|
|
|
$expectedQuery = [ |
20
|
|
|
'AttributeDefinitions' => [ |
21
|
|
|
[ |
22
|
|
|
'AttributeName' => 'test', |
23
|
|
|
'AttributeType' => AttributeTypes::STRING, |
24
|
|
|
], |
25
|
|
|
], |
26
|
|
|
'KeySchema' => [ |
27
|
|
|
[ |
28
|
|
|
'AttributeName' => 'test', |
29
|
|
|
'KeyType' => KeyTypes::HASH, |
30
|
|
|
], |
31
|
|
|
], |
32
|
|
|
'ProvisionedThroughput' => [ |
33
|
|
|
'ReadCapacityUnits' => 5, |
34
|
|
|
'WriteCapacityUnits' => 5, |
35
|
|
|
], |
36
|
|
|
'TableName' => 'test', |
37
|
|
|
]; |
38
|
|
|
$this->assertEquals($expectedQuery, $request->toArray()); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testSetSortKey() |
42
|
|
|
{ |
43
|
|
|
$request = new CreateTableRequest(new Marshaler(), 'test'); |
44
|
|
|
$request->setSortKey('test', AttributeTypes::STRING); |
45
|
|
|
$expectedQuery = [ |
46
|
|
|
'AttributeDefinitions' => [ |
47
|
|
|
[ |
48
|
|
|
'AttributeName' => 'test', |
49
|
|
|
'AttributeType' => AttributeTypes::STRING, |
50
|
|
|
], |
51
|
|
|
], |
52
|
|
|
'KeySchema' => [ |
53
|
|
|
[ |
54
|
|
|
'AttributeName' => 'test', |
55
|
|
|
'KeyType' => KeyTypes::RANGE, |
56
|
|
|
], |
57
|
|
|
], |
58
|
|
|
'ProvisionedThroughput' => [ |
59
|
|
|
'ReadCapacityUnits' => 5, |
60
|
|
|
'WriteCapacityUnits' => 5, |
61
|
|
|
], |
62
|
|
|
'TableName' => 'test', |
63
|
|
|
]; |
64
|
|
|
$this->assertEquals($expectedQuery, $request->toArray()); |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
public function testSetKeySchema() |
68
|
|
|
{ |
69
|
|
|
$request = new CreateTableRequest(new Marshaler(), 'test', $this->data); |
70
|
|
|
$expectedQuery = [ |
71
|
|
|
'AttributeDefinitions' => [ |
72
|
|
|
[ |
73
|
|
|
'AttributeName' => 'name', |
74
|
|
|
'AttributeType' => AttributeTypes::STRING, |
75
|
|
|
], |
76
|
|
|
], |
77
|
|
|
'KeySchema' => [ |
78
|
|
|
[ |
79
|
|
|
'AttributeName' => 'name', |
80
|
|
|
'KeyType' => KeyTypes::HASH, |
81
|
|
|
], |
82
|
|
|
], |
83
|
|
|
'ProvisionedThroughput' => [ |
84
|
|
|
'ReadCapacityUnits' => 5, |
85
|
|
|
'WriteCapacityUnits' => 5, |
86
|
|
|
], |
87
|
|
|
'TableName' => 'test', |
88
|
|
|
]; |
89
|
|
|
$this->assertEquals($expectedQuery, $request->toArray()); |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public function testSetReadCapacityUnits() |
93
|
|
|
{ |
94
|
|
|
$request = new CreateTableRequest(new Marshaler(), 'test', $this->data); |
95
|
|
|
$request->setReadCapacityUnits(10); |
96
|
|
|
$expectedQuery = [ |
97
|
|
|
'AttributeDefinitions' => [ |
98
|
|
|
[ |
99
|
|
|
'AttributeName' => 'name', |
100
|
|
|
'AttributeType' => AttributeTypes::STRING, |
101
|
|
|
], |
102
|
|
|
], |
103
|
|
|
'KeySchema' => [ |
104
|
|
|
[ |
105
|
|
|
'AttributeName' => 'name', |
106
|
|
|
'KeyType' => KeyTypes::HASH, |
107
|
|
|
], |
108
|
|
|
], |
109
|
|
|
'ProvisionedThroughput' => [ |
110
|
|
|
'ReadCapacityUnits' => 10, |
111
|
|
|
'WriteCapacityUnits' => 5, |
112
|
|
|
], |
113
|
|
|
'TableName' => 'test', |
114
|
|
|
]; |
115
|
|
|
$this->assertEquals($expectedQuery, $request->toArray()); |
116
|
|
|
} |
117
|
|
|
|
118
|
|
|
public function testWriteCapacityUnits() |
119
|
|
|
{ |
120
|
|
|
$request = new CreateTableRequest(new Marshaler(), 'test', $this->data); |
121
|
|
|
$request->setWriteCapacityUnits(20); |
122
|
|
|
$expectedQuery = [ |
123
|
|
|
'AttributeDefinitions' => [ |
124
|
|
|
[ |
125
|
|
|
'AttributeName' => 'name', |
126
|
|
|
'AttributeType' => AttributeTypes::STRING, |
127
|
|
|
], |
128
|
|
|
], |
129
|
|
|
'KeySchema' => [ |
130
|
|
|
[ |
131
|
|
|
'AttributeName' => 'name', |
132
|
|
|
'KeyType' => KeyTypes::HASH, |
133
|
|
|
], |
134
|
|
|
], |
135
|
|
|
'ProvisionedThroughput' => [ |
136
|
|
|
'ReadCapacityUnits' => 5, |
137
|
|
|
'WriteCapacityUnits' => 20, |
138
|
|
|
], |
139
|
|
|
'TableName' => 'test', |
140
|
|
|
]; |
141
|
|
|
$this->assertEquals($expectedQuery, $request->toArray()); |
142
|
|
|
} |
143
|
|
|
} |
144
|
|
|
|