Completed
Push — master ( a7a349...3fc402 )
by Guillermo A.
03:23
created

QueryOperationTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 16
c 0
b 0
f 0
dl 0
loc 36
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testSetSortKeyConditionExpression() 0 11 1
A tearDown() 0 3 1
A testSetPartitionKeyConditionExpression() 0 6 1
A setUp() 0 3 1
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 testSetPartitionKeyConditionExpression()
19
    {
20
        $this->request->setPartitionKeyConditionExpression('test', 'something');
21
        $requestArray = $this->request->toArray();
22
        $this->assertEquals('test = :test', $requestArray['KeyConditionExpression']);
23
        $this->assertEquals(['S' => 'something'], $requestArray['ExpressionAttributeValues'][':test']);
24
    }
25
26
    public function testSetSortKeyConditionExpression()
27
    {
28
        $this->request->setPartitionKeyConditionExpression('test', 'something');
29
        $this->request->setSortKeyConditionExpression('anotherTest', Operators::BEGINS_WITH, 'somethingElse');
30
        $requestArray = $this->request->toArray();
31
        $this->assertEquals(
32
            'test = :test AND begins_with(anotherTest, :anotherTest)',
33
            $requestArray['KeyConditionExpression']
34
        );
35
        $this->assertEquals(['S' => 'something'], $requestArray['ExpressionAttributeValues'][':test']);
36
        $this->assertEquals(['S' => 'somethingElse'], $requestArray['ExpressionAttributeValues'][':anotherTest']);
37
    }
38
39
    protected function setUp(): void
40
    {
41
        $this->request = new QueryOperation(DynamoDbClientFactory::factory(), MarshalerFactory::factory(), 'test');
42
    }
43
44
    protected function tearDown(): void
45
    {
46
        $this->request = null;
47
    }
48
}
49