Completed
Push — master ( 19c355...d500cb )
by Guillermo A.
02:33
created

QueryOperationTest::testSetLimit()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
c 0
b 0
f 0
dl 0
loc 5
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace GuillermoandraeTest\DynamoDb\Operation;
4
5
use Guillermoandrae\DynamoDb\Constant\Operators;
6
use Guillermoandrae\DynamoDb\Factory\DynamoDbClientFactory;
7
use Guillermoandrae\DynamoDb\Factory\MarshalerFactory;
8
use Guillermoandrae\DynamoDb\Operation\QueryOperation;
9
use PHPUnit\Framework\TestCase;
10
11
final class QueryOperationTest extends TestCase
12
{
13
    /**
14
     * @var QueryOperation The request.
15
     */
16
    private $request;
17
18
    public function testSetLimit()
19
    {
20
        $expectedLimit = 50;
21
        $this->request->setLimit($expectedLimit);
22
        $this->assertEquals($expectedLimit, $this->request->toArray()['Limit']);
23
    }
24
25
    public function testSetReturnConsumedCapacity()
26
    {
27
        $expectedReturnConsumedCapacity = 50;
28
        $this->request->setReturnConsumedCapacity($expectedReturnConsumedCapacity);
29
        $this->assertEquals($expectedReturnConsumedCapacity, $this->request->toArray()['ReturnConsumedCapacity']);
30
    }
31
32
    public function testSetPartitionKeyConditionExpression()
33
    {
34
        $this->request->setPartitionKeyConditionExpression('test', 'something');
35
        $requestArray = $this->request->toArray();
36
        $this->assertEquals('test = :test', $requestArray['KeyConditionExpression']);
37
        $this->assertEquals(['S' => 'something'], $requestArray['ExpressionAttributeValues'][':test']);
38
    }
39
40
    public function testSetSortKeyConditionExpression()
41
    {
42
        $this->request->setPartitionKeyConditionExpression('test', 'something');
43
        $this->request->setSortKeyConditionExpression('anotherTest', Operators::BEGINS_WITH, 'somethingElse');
44
        $requestArray = $this->request->toArray();
45
        $this->assertEquals(
46
            'test = :test AND begins_with(anotherTest, :anotherTest)',
47
            $requestArray['KeyConditionExpression']
48
        );
49
        $this->assertEquals(['S' => 'something'], $requestArray['ExpressionAttributeValues'][':test']);
50
        $this->assertEquals(['S' => 'somethingElse'], $requestArray['ExpressionAttributeValues'][':anotherTest']);
51
    }
52
53
    protected function setUp(): void
54
    {
55
        $this->request = new QueryOperation(DynamoDbClientFactory::factory(), MarshalerFactory::factory(), 'test');
56
    }
57
58
    protected function tearDown(): void
59
    {
60
        $this->request = null;
61
    }
62
}
63