|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace GuillermoandraeTest\Db\DynamoDb; |
|
4
|
|
|
|
|
5
|
|
|
use Aws\DynamoDb\Marshaler; |
|
6
|
|
|
use Guillermoandrae\Db\DynamoDb\QueryRequest; |
|
7
|
|
|
use Guillermoandrae\Db\DynamoDb\RequestOperators; |
|
8
|
|
|
use PHPUnit\Framework\TestCase; |
|
9
|
|
|
|
|
10
|
|
|
final class QueryRequestTest extends TestCase |
|
11
|
|
|
{ |
|
12
|
|
|
/** |
|
13
|
|
|
* @var QueryRequest The request. |
|
14
|
|
|
*/ |
|
15
|
|
|
private $request; |
|
16
|
|
|
|
|
17
|
|
|
public function testSetPartitionKeyConditionExpression() |
|
18
|
|
|
{ |
|
19
|
|
|
$this->request->setPartitionKeyConditionExpression('test', RequestOperators::GTE, 'something'); |
|
20
|
|
|
$requestArray = $this->request->toArray(); |
|
21
|
|
|
$this->assertEquals('test >= :test', $requestArray['KeyConditionExpression']); |
|
22
|
|
|
$this->assertEquals(['S' => 'something'], $requestArray['ExpressionAttributeValues'][':test']); |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
public function testSetSortKeyConditionExpression() |
|
26
|
|
|
{ |
|
27
|
|
|
$this->request->setPartitionKeyConditionExpression('test', RequestOperators::GTE, 'something'); |
|
28
|
|
|
$this->request->setSortKeyConditionExpression('anotherTest', RequestOperators::BEGINS_WITH, 'somethingElse'); |
|
29
|
|
|
$requestArray = $this->request->toArray(); |
|
30
|
|
|
$this->assertEquals( |
|
31
|
|
|
'test >= :test AND begins_with(anotherTest, :anotherTest)', |
|
32
|
|
|
$requestArray['KeyConditionExpression'] |
|
33
|
|
|
); |
|
34
|
|
|
$this->assertEquals(['S' => 'something'], $requestArray['ExpressionAttributeValues'][':test']); |
|
35
|
|
|
$this->assertEquals(['S' => 'somethingElse'], $requestArray['ExpressionAttributeValues'][':anotherTest']); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
protected function setUp(): void |
|
39
|
|
|
{ |
|
40
|
|
|
$this->request = new QueryRequest(new Marshaler(), 'test'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
protected function tearDown(): void |
|
44
|
|
|
{ |
|
45
|
|
|
$this->request = null; |
|
46
|
|
|
} |
|
47
|
|
|
} |
|
48
|
|
|
|