SendTokenListDataDirectiveTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 29
c 1
b 0
f 1
dl 0
loc 44
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testAddItem() 0 10 1
A testConstructorAndSerialization() 0 16 1
A testSerializationOmitsNullAndEmpty() 0 12 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace MaxBeckers\AmazonAlexa\Test\Response\Directives\APL;
6
7
use MaxBeckers\AmazonAlexa\Response\Directives\APL\SendTokenListDataDirective;
8
use PHPUnit\Framework\TestCase;
9
10
class SendTokenListDataDirectiveTest extends TestCase
11
{
12
    public function testConstructorAndSerialization(): void
13
    {
14
        $d = new SendTokenListDataDirective(
15
            listId: 'list-x',
16
            pageToken: 'page-1',
17
            correlationToken: 'corr-123',
18
            nextPageToken: 'page-2'
19
        );
20
21
        $json = $d->jsonSerialize();
22
        $this->assertSame(SendTokenListDataDirective::TYPE, $json['type']);
23
        $this->assertSame('list-x', $json['listId']);
24
        $this->assertSame('page-1', $json['pageToken']);
25
        $this->assertSame('corr-123', $json['correlationToken']);
26
        $this->assertSame('page-2', $json['nextPageToken']);
27
        $this->assertArrayNotHasKey('items', $json);
28
    }
29
30
    public function testAddItem(): void
31
    {
32
        $d = new SendTokenListDataDirective('list-z', 'p');
33
        $d->addItem(['k' => 'v']);
34
        $d->addItem(['k' => 'w']);
35
36
        $json = $d->jsonSerialize();
37
        $this->assertArrayHasKey('items', $json);
38
        $this->assertCount(2, $json['items']);
39
        $this->assertSame(['k' => 'v'], $json['items'][0]);
40
    }
41
42
    public function testSerializationOmitsNullAndEmpty(): void
43
    {
44
        $d = new SendTokenListDataDirective('list-empty', 'token-empty');
45
        $json = $d->jsonSerialize();
46
47
        $this->assertSame(SendTokenListDataDirective::TYPE, $json['type']);
48
        $this->assertSame('list-empty', $json['listId']);
49
        $this->assertSame('token-empty', $json['pageToken']);
50
        $this->assertCount(3, $json); // type, listId, pageToken
51
        $this->assertArrayNotHasKey('items', $json);
52
        $this->assertArrayNotHasKey('correlationToken', $json);
53
        $this->assertArrayNotHasKey('nextPageToken', $json);
54
    }
55
}
56