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\Factory\DynamoDbClientFactory; |
9
|
|
|
use Guillermoandrae\DynamoDb\Factory\MarshalerFactory; |
10
|
|
|
use Guillermoandrae\DynamoDb\Operation\CreateTableOperation; |
11
|
|
|
use PHPUnit\Framework\TestCase; |
12
|
|
|
|
13
|
|
|
final class CreateTableOperationTest extends TestCase |
14
|
|
|
{ |
15
|
|
|
private $data = ['name' => ['attributeType' => AttributeTypes::STRING, 'keyType' => KeyTypes::HASH]]; |
16
|
|
|
|
17
|
|
|
public function testSetPartitionKey() |
18
|
|
|
{ |
19
|
|
|
$request = new CreateTableOperation( |
20
|
|
|
DynamoDbClientFactory::factory(), |
21
|
|
|
MarshalerFactory::factory(), |
22
|
|
|
'test' |
23
|
|
|
); |
24
|
|
|
$request->setPartitionKey('test', AttributeTypes::STRING); |
25
|
|
|
$this->assertEquals(KeyTypes::HASH, $request->toArray()['KeySchema'][0]['KeyType']); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
public function testSetSortKey() |
29
|
|
|
{ |
30
|
|
|
$request = new CreateTableOperation( |
31
|
|
|
DynamoDbClientFactory::factory(), |
32
|
|
|
MarshalerFactory::factory(), |
33
|
|
|
'test' |
34
|
|
|
); |
35
|
|
|
$request->setSortKey('test', AttributeTypes::STRING); |
36
|
|
|
$this->assertEquals(KeyTypes::RANGE, $request->toArray()['KeySchema'][0]['KeyType']); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
public function testSetReadCapacityUnits() |
40
|
|
|
{ |
41
|
|
|
$request = new CreateTableOperation( |
42
|
|
|
DynamoDbClientFactory::factory(), |
43
|
|
|
MarshalerFactory::factory(), |
44
|
|
|
'test', |
45
|
|
|
$this->data |
46
|
|
|
); |
47
|
|
|
$request->setReadCapacityUnits(10); |
48
|
|
|
$this->assertEquals(10, $request->toArray()['ProvisionedThroughput']['ReadCapacityUnits']); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
public function testWriteCapacityUnits() |
52
|
|
|
{ |
53
|
|
|
$request = new CreateTableOperation( |
54
|
|
|
DynamoDbClientFactory::factory(), |
55
|
|
|
MarshalerFactory::factory(), |
56
|
|
|
'test', |
57
|
|
|
$this->data |
58
|
|
|
); |
59
|
|
|
$request->setWriteCapacityUnits(20); |
60
|
|
|
$this->assertEquals(20, $request->toArray()['ProvisionedThroughput']['WriteCapacityUnits']); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
public function testSetBillingMode() |
64
|
|
|
{ |
65
|
|
|
$request = new CreateTableOperation( |
66
|
|
|
DynamoDbClientFactory::factory(), |
67
|
|
|
MarshalerFactory::factory(), |
68
|
|
|
'test', |
69
|
|
|
$this->data |
70
|
|
|
); |
71
|
|
|
$request->setBillingMode(BillingModes::PAY_PER_REQUEST); |
72
|
|
|
$this->assertEquals(BillingModes::PAY_PER_REQUEST, $request->toArray()['BillingMode']); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function testSSESpecification() |
76
|
|
|
{ |
77
|
|
|
$request = new CreateTableOperation( |
78
|
|
|
DynamoDbClientFactory::factory(), |
79
|
|
|
MarshalerFactory::factory(), |
80
|
|
|
'test', |
81
|
|
|
$this->data |
82
|
|
|
); |
83
|
|
|
$request->setSSESpecification(true, 'someKey'); |
84
|
|
|
$this->assertEquals('someKey', $request->toArray()['SSESpecification']['KMSMasterKeyId']); |
85
|
|
|
$request->setSSESpecification(false); |
86
|
|
|
$this->assertArrayNotHasKey('SSESpecification', $request->toArray()); |
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
public function testAddTag() |
90
|
|
|
{ |
91
|
|
|
$request = new CreateTableOperation( |
92
|
|
|
DynamoDbClientFactory::factory(), |
93
|
|
|
MarshalerFactory::factory(), |
94
|
|
|
'test', |
95
|
|
|
$this->data |
96
|
|
|
); |
97
|
|
|
$request->addTag('someKey', 'someValue'); |
98
|
|
|
$request->addTag('anotherKey', 'anotherValue'); |
99
|
|
|
$this->assertEquals('someValue', $request->toArray()['Tags'][0]['Value']); |
100
|
|
|
$this->assertEquals('anotherValue', $request->toArray()['Tags'][1]['Value']); |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
|