1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace GuillermoandraeTest\DynamoDb; |
4
|
|
|
|
5
|
|
|
use Aws\DynamoDb\Marshaler; |
6
|
|
|
use Guillermoandrae\DynamoDb\AbstractFilterExpressionAwareRequest; |
7
|
|
|
use Guillermoandrae\DynamoDb\RequestOperators; |
8
|
|
|
use PHPUnit\Framework\TestCase; |
9
|
|
|
|
10
|
|
|
final class FilterExpressionAwareRequestTest extends TestCase |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @var AbstractFilterExpressionAwareRequest The request. |
14
|
|
|
*/ |
15
|
|
|
private $request; |
16
|
|
|
|
17
|
|
|
public function testFilterExpressionGT() |
18
|
|
|
{ |
19
|
|
|
$expectedExpression = 'width > :width'; |
20
|
|
|
$this->request->setFilterExpression([ |
21
|
|
|
'width' => [ |
22
|
|
|
'operator' => RequestOperators::GT, |
23
|
|
|
'value' => '10', |
24
|
|
|
] |
25
|
|
|
]); |
26
|
|
|
$this->assertEquals($expectedExpression, $this->request->toArray()['FilterExpression']); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function testFilterExpressionGTE() |
30
|
|
|
{ |
31
|
|
|
$expectedExpression = 'width >= :width'; |
32
|
|
|
$this->request->setFilterExpression([ |
33
|
|
|
'width' => [ |
34
|
|
|
'operator' => RequestOperators::GTE, |
35
|
|
|
'value' => '10', |
36
|
|
|
] |
37
|
|
|
]); |
38
|
|
|
$this->assertEquals($expectedExpression, $this->request->toArray()['FilterExpression']); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
public function testFilterExpressionLT() |
42
|
|
|
{ |
43
|
|
|
$expectedExpression = 'width < :width'; |
44
|
|
|
$this->request->setFilterExpression([ |
45
|
|
|
'width' => [ |
46
|
|
|
'operator' => RequestOperators::LT, |
47
|
|
|
'value' => '10', |
48
|
|
|
] |
49
|
|
|
]); |
50
|
|
|
$this->assertEquals($expectedExpression, $this->request->toArray()['FilterExpression']); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
public function testFilterExpressionLTE() |
54
|
|
|
{ |
55
|
|
|
$expectedExpression = 'width <= :width'; |
56
|
|
|
$this->request->setFilterExpression([ |
57
|
|
|
'width' => [ |
58
|
|
|
'operator' => RequestOperators::LTE, |
59
|
|
|
'value' => '10', |
60
|
|
|
] |
61
|
|
|
]); |
62
|
|
|
$this->assertEquals($expectedExpression, $this->request->toArray()['FilterExpression']); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function testFilterExpressionBadOperator() |
66
|
|
|
{ |
67
|
|
|
$this->expectException(\ErrorException::class); |
68
|
|
|
$this->request->setFilterExpression([ |
69
|
|
|
'width' => [ |
70
|
|
|
'operator' => 'TEST', |
71
|
|
|
'value' => '10', |
72
|
|
|
] |
73
|
|
|
]); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
public function testSetFilterExpressionAndExpressionAttributeValues() |
77
|
|
|
{ |
78
|
|
|
$this->request->setFilterExpression([ |
79
|
|
|
'color' => [ |
80
|
|
|
'operator' => RequestOperators::EQ, |
81
|
|
|
'value' => 'black', |
82
|
|
|
], |
83
|
|
|
'shape' => [ |
84
|
|
|
'operator' => RequestOperators::CONTAINS, |
85
|
|
|
'value' => 'square' |
86
|
|
|
], |
87
|
|
|
'width' => [ |
88
|
|
|
'operator' => RequestOperators::GTE, |
89
|
|
|
'value' => 10 |
90
|
|
|
] |
91
|
|
|
]); |
92
|
|
|
$expectedQuery = [ |
93
|
|
|
'TableName' => 'test', |
94
|
|
|
'ReturnConsumedCapacity' => 'NONE', |
95
|
|
|
'FilterExpression' => 'color = :color and contains(shape, :shape) and width >= :width', |
96
|
|
|
'ExpressionAttributeValues' => [ |
97
|
|
|
':color' => [ |
98
|
|
|
'S' => 'black' |
99
|
|
|
], |
100
|
|
|
':shape' => [ |
101
|
|
|
'S' => 'square', |
102
|
|
|
], |
103
|
|
|
':width' => [ |
104
|
|
|
'N' => 10 |
105
|
|
|
] |
106
|
|
|
], |
107
|
|
|
]; |
108
|
|
|
$this->assertEquals($expectedQuery, $this->request->toArray()); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
public function testSetReturnConsumedCapacity() |
112
|
|
|
{ |
113
|
|
|
$this->request->setReturnConsumedCapacity('INDEXES'); |
114
|
|
|
$expectedQuery = [ |
115
|
|
|
'TableName' => 'test', |
116
|
|
|
'ReturnConsumedCapacity' => 'INDEXES' |
117
|
|
|
]; |
118
|
|
|
$this->assertEquals($expectedQuery, $this->request->toArray()); |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
public function testSetLimit() |
122
|
|
|
{ |
123
|
|
|
$this->request->setLimit(2); |
124
|
|
|
$expectedQuery = [ |
125
|
|
|
'TableName' => 'test', |
126
|
|
|
'ReturnConsumedCapacity' => 'NONE', |
127
|
|
|
'Limit' => 2 |
128
|
|
|
]; |
129
|
|
|
$this->assertEquals($expectedQuery, $this->request->toArray()); |
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
protected function setUp(): void |
133
|
|
|
{ |
134
|
|
|
$this->request = $this->getMockForAbstractClass( |
|
|
|
|
135
|
|
|
AbstractFilterExpressionAwareRequest::class, |
136
|
|
|
[new Marshaler(), 'test'] |
137
|
|
|
); |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
protected function tearDown(): void |
141
|
|
|
{ |
142
|
|
|
$this->request = null; |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..